#!/usr/bin/perl #--------------------------------------------------------------------------------------------- $eyeFile = $ARGV[0]; @supercellEdge = (0, 0 ,0); @cellsPerSupercell = (10, 10, 16); open (READIT, $eyeFile) || die("** Can't read file! ** \nScript use: perl ab_split.pl [input].cfg\n"); @eyeIn = ; close (READIT); print "\nDone reading in file $eyeFile \n"; print "\nEnter the number of unit cells in each direction (default @cellsPerSupercell): "; $userInput = ; chomp($userInput); if ($userInput ne "") { @cellsPerSupercell = split(" ",$userInput); } if ($#cellsPerSupercell != 2) {exit;} $i=0; foreach (@eyeIn) { chomp(); if (/Number of particles \=/) { $totalAtoms = trim($'); } if (/H0\(1,1\) = /) { $supercellEdge[0] = trim($'); } if (/H0\(2,2\) = /) { $supercellEdge[1] = trim($'); } if (/H0\(3,3\) = /) { $supercellEdge[2] = trim($'); } if (!/^\w/) { push(@atomIn, $eyeIn[$i]); } $i++; } $i=0; foreach (@supercellEdge) { chop; chop; print "Direction $i has $supercellEdge[$i] A supercell and $cellsPerSupercell[$i] unit cells of "; $unitCellEdge[$i] = $supercellEdge[$i]/$cellsPerSupercell[$i]; print "$unitCellEdge[$i] A.\n"; $i++; } print "I found $totalAtoms atoms. Folding into a single cell now...\n"; $i=0; $j=0; $k=0; foreach (@atomIn) { my @atomLine = split(/\s+/, $atomIn[$i]); for ($j = 0; $j < 3; $j++) { $atomLine[3+$j] = sprintf("%.5f",(mod($atomLine[3+$j]*$cellsPerSupercell[$j],1))); } $atomOut[$i] = join(" ",@atomLine); $i++; } print "Done! Creating new eye file...\n"; $i=0; foreach (@eyeIn) { if (/H0\(1,1\) = /) { push(@eyeOut,"H0(1,1) = $unitCellEdge[0] A"); } elsif (/H0\(2,2\) = /) { push(@eyeOut,"H0(2,2) = $unitCellEdge[1] A"); } elsif (/H0\(3,3\) = /) { push(@eyeOut,"H0(3,3) = $unitCellEdge[2] A"); } elsif (/basic/) { push(@eyeOut,"A = 1000 Angstrom (basic length-scale)"); } elsif (!/^\w/) { push(@eyeOut, $atomOut[$i-17]); #note the cfg preamble should be 17 lines } else { push(@eyeOut, $eyeIn[$i]); } $i++; } $eyeFile =~ s/\.cfg/\_fold\.cfg/; print "\nDone! Writing output to $eyeFile. Check it out with:\n\n atomeye $eyeFile \n\n"; print "Or clear out duplicates with:\n\n rmc-removeduplicates $eyeFile \n\n"; open (WRITEXYZ, ">$eyeFile") || die("** Can't read file! ** \nScript use: perl ab_split.pl [output].cfg\n"); print WRITEXYZ join("\n",@eyeOut); close (WRITEXYZ); print "All finished!\n\n"; sub mod { return $_[0] - int ($_[0] / $_[1]) * $_[1]; }; sub trim($) { my $foo = shift; $foo =~ s/^\s+//; $foo =~ s/\s+$//; return $foo; }