#!/usr/bin/perl # This is a ripoff of rmc_to_atomeye from the rmc package, works on version 3 cfg files. # Not totally sure if it is compatible with non-90degree cell angles. someone should test it! #--------------------------------------------------------------------------------------------- $cfgFile = $ARGV[0]; @supercellEdge = (0, 0 ,0); @cellsPerSupercell = (10, 10, 16); open (READIT, $cfgFile) || die("** Can't read file! ** \nScript use: perl ab_split.pl [input].cfg\n"); @cfgIn = ; close (READIT); print "\nDone reading in file $cfgFile \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; $numTypes=0; $totalAtomsInArray=0; $foundVectors = 0; foreach (@cfgIn) { chomp(); if (/molecules \(of all types\)/) { $totalAtomsClaimed = trim($`); print "This file claims there are $totalAtomsClaimed total atoms\n"; } if (/molecules of type/) { $numAtoms[$numTypes] = trim($`); print "$numAtoms[$numTypes] of type $numTypes\n"; $numTypes++; } if (/Defining vectors are/) { $foundVectors = $i; } if (($foundVectors > 0) && (($i == $foundVectors+1) || ($i == $foundVectors+2) || ($i == $foundVectors+3))) { $HLine = trim($_); print "line is $Hline \n"; @HValues = split(/\s+/,$HLine); print "values are @HValues \n"; for ($j=0; $j < 3; $j++) { push(@H0matrix, $HValues[$j]); } print "matrix is @H0matrix\n"; } if ((!/^ /) && ($i > 20) && (/\./)) { $atomLine = trim($_); @atomLineArray = split(/\s+/,$atomLine); for ($j=0; $j < 3; $j++) { $atomIn[$totalAtomsInArray][$j] = @atomLineArray[$j]; } $totalAtomsInArray++; } $i++; } if ($totalAtomsClaimed == $totalAtomsInArray) { print "Total number of atoms is $totalAtomsInArray\n\n"; } else { print "Mismatch in number of atoms claimed versus found!!\n"; exit; } $datFile = $cfgFile; $datFile =~ s/\.cfg/\.dat/; open (READTYPES, $datFile) || print "I don't see a RMC .dat file with atom type info...\n"; @datIn = ; close (READTYPES); foreach (@datIn) { chomp(); if (/^ATOMS :: /) { $datAtomNames = trim($'); @atomSymbol = split(/\s+/,$datAtomNames); $foundAtomNames = 1; print "Nice job! Found the atom types in $datFile : @atomSymbol \n"; print "Do you want to use these names? ([enter] / n): "; $userInput = ; chomp($userInput); if ($userInput eq "n") { $foundAtomNames = 0; } } } if ($foundAtomNames != 1) { for ($i = 0; $i<$numTypes; $i++) { print "\nEnter the symbol for atom type $i: "; $userInput = ; chomp($userInput); if ($userInput ne "") { $atomSymbol[$i] = $userInput; } else { exit; } } } for ($i=0; $i<$totalAtomsInArray; $i++) { for ($j=0; $j<3; $j++) { $atomOut[$i][$j] = sprintf("%.8f",$atomIn[$i][$j]*0.5 + 0.5); } } for ($i=0; $i<9; $i++) { $H0matrix[$i] = $H0matrix[$i]*2; } push(@eyeOut, "Number of particles = $totalAtomsInArray"); push(@eyeOut, "A = 1.0 Angstrom (basic length-scale)"); push(@eyeOut, "H0(1,1) = $H0matrix[0] A"); push(@eyeOut, "H0(1,2) = $H0matrix[1] A"); push(@eyeOut, "H0(1,3) = $H0matrix[2] A"); push(@eyeOut, "H0(2,1) = $H0matrix[3] A"); push(@eyeOut, "H0(2,2) = $H0matrix[4] A"); push(@eyeOut, "H0(2,3) = $H0matrix[5] A"); push(@eyeOut, "H0(3,1) = $H0matrix[6] A"); push(@eyeOut, "H0(3,2) = $H0matrix[7] A"); push(@eyeOut, "H0(3,3) = $H0matrix[8] A"); push(@eyeOut, "eta(1,1) = 0"); push(@eyeOut, "eta(1,2) = 0"); push(@eyeOut, "eta(1,3) = 0"); push(@eyeOut, "eta(2,2) = 0"); push(@eyeOut, "eta(2,3) = 0"); push(@eyeOut, "eta(3,3) = 0"); $currentAtom=0; for ($i = 0; $i<$numTypes; $i++) { for ($j=0; $j<$numAtoms[$i]; $j++) { push(@eyeOut, " 0.000 $atomSymbol[$i] $atomOut[$currentAtom][0] $atomOut[$currentAtom][1] $atomOut[$currentAtom][2] 0 0 0"); $currentAtom++; } } $cfgFile =~ s/\.cfg/\_eye\.cfg/; print "\nDone! Writing output to $cfgFile, examine with\n\natomeye $cfgFile\n\n"; open (WRITEXYZ, ">$cfgFile") || die("** Can't read file! ** \nScript use: perl ab_split.pl [output].cfg\n"); print WRITEXYZ join("\n",@eyeOut); close (WRITEXYZ); sub mod { return $_[0] - int ($_[0] / $_[1]) * $_[1]; }; sub trim($) { my $foo = shift; $foo =~ s/^\s+//; $foo =~ s/\s+$//; return $foo; }