(* Content-type: application/mathematica *) (*** Wolfram Notebook File ***) (* http://www.wolfram.com/nb *) (* CreatedBy='Mathematica 6.0' *) (*CacheID: 234*) (* Internal cache information: NotebookFileLineBreakTest NotebookFileLineBreakTest NotebookDataPosition[ 145, 7] NotebookDataLength[ 39206, 958] NotebookOptionsPosition[ 38290, 920] NotebookOutlinePosition[ 38705, 938] CellTagsIndexPosition[ 38662, 935] WindowFrame->Normal*) (* Beginning of Notebook Content *) Notebook[{ Cell[CellGroupData[{ Cell[" vasp2gview-2.0", "Title", WindowToolbars->"RulerBar", Magnification->1.5], Cell[CellGroupData[{ Cell["Script Info", "Section", FontColor->GrayLevel[0.5]], Cell[TextData[{ "What's this: This script converts Vasp POSCAR/CONTCAR to \ Gaussian/Gaussview .com /.gjf files. \n", "What's new: ", StyleBox["Graphic User Interface added", FontWeight->"Bold"], "." }], "Text"], Cell[CellGroupData[{ Cell["Version: 2.0.", "Subsubsection"], Cell["\<\ 1. Last updated on 2009-04-17. by chao cwu4~nd.edu. 2. If you convert this script to either real scripts or exe codes, please \ give me a copy. Thanks a lot! 3. Any bug, please also tell me.\ \>", "Text"] }, Closed]], Cell[CellGroupData[{ Cell["Default settings:", "Subsubsection"], Cell[TextData[{ "1. .com file will be saved in the same folder;\n2. POTCAR is ", StyleBox["required", FontWeight->"Bold"], " in the same folder of input file (POSCAR/CONTAR) to identify elements;\n3. \ The translational vectors written to the Gaussian file have been multiplied \ by the scale factor; \n4. Precision of the numbers: 7th behind decimal place.\ \n5. Format other than POSCAR/CONTCAR will result into errors." }], "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell["Script [shift+enter to execute]", "Section"], Cell[BoxData[{ RowBox[{ RowBox[{ RowBox[{"Clear", "[", "\"\\"", "]"}], ";"}], "\[IndentingNewLine]", " ", RowBox[{"(*", " ", RowBox[{ "switch", " ", "to", " ", "current", " ", "directory", " ", "before", " ", "start"}], "*)"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{"use", " ", "GUIKit", " ", "for", " ", "GUI"}], "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"Needs", "[", "\"\\"", "]"}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"NotebookDirectory", "[", "]"}], " ", "inside", " ", "the", " ", "self"}], "-", RowBox[{ "defined", " ", "function", " ", "always", " ", "gives", " ", "$failed", " ", "info"}]}], "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"nbDirectory", "=", RowBox[{"NotebookDirectory", "[", "]"}]}], ";"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"--", "generate"}], " ", "GUI", " ", "input", " ", "dialog", " ", RowBox[{"box", "--"}], RowBox[{"begin", "--"}]}], "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"inputDialogBox", " ", "=", " ", RowBox[{"GUIRun", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{ "\"\\"", "\[Rule]", " ", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"\"\\"", "\[Rule]", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"BindEvent", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"Script", "[", "\[IndentingNewLine]", RowBox[{"GUIResolve", "[", "\[IndentingNewLine]", RowBox[{"Script", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"Name", "\[Rule]", "\"\\""}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"SetPropertyValue", "[", RowBox[{ RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\""}], "}"}], ",", "False"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"SetPropertyValue", "[", RowBox[{ RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\""}], "}"}], ",", RowBox[{"PropertyValue", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\""}], "}"}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"SetPropertyValue", "[", RowBox[{ RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\""}], "}"}], ",", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"InitialArguments", "\[Rule]", RowBox[{"{", "nbDirectory", "}"}]}]}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"returnValue", "=", RowBox[{"InvokeMethod", "[", RowBox[{ RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\""}], "}"}], ",", "Null"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"returnValue", "===", RowBox[{"PropertyValue", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\""}], "}"}], "]"}]}], ",", RowBox[{ RowBox[{"fileSelected", "=", RowBox[{"PropertyValue", "[", RowBox[{"{", RowBox[{ RowBox[{"PropertyValue", "[", RowBox[{"{", RowBox[{ "\"\\"", ",", "\"\\""}], "}"}], "]"}], ",", "\"\\""}], "}"}], "]"}]}], ";", RowBox[{"SetPropertyValue", "[", RowBox[{ RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}], ",", RowBox[{"DirectoryName", "[", "fileSelected", "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"SetPropertyValue", "[", RowBox[{ RowBox[{"{", RowBox[{"\"\\"", ",", "\"\\""}], "}"}], ",", " ", RowBox[{"FileNameTake", "[", "fileSelected", "]"}]}], "]"}]}], ",", "\[IndentingNewLine]", "Null"}], "]"}]}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "}"}], ",", RowBox[{"Name", "\[Rule]", "\"\\""}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"\"\\"", " ", "\[Rule]", " ", RowBox[{"ToString", "[", "nbDirectory", "]"}]}], "}"}], ",", RowBox[{"Name", "\[Rule]", " ", "\"\\""}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"\"\\"", "->", "\"\\""}], "}"}], ",", RowBox[{"WidgetLayout", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", "\[Rule]", "Left"}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"\"\\"", "->", "\"\\""}], "}"}], ",", " ", RowBox[{"Name", "\[Rule]", " ", "\"\\""}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ "\"\\"", "->", "\"\\""}], "}"}], ",", RowBox[{"WidgetLayout", "\[Rule]", RowBox[{"{", RowBox[{"\"\\"", "\[Rule]", "Left"}], "}"}]}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{"\"\\"", "->", "\"\\""}], "}"}], ",", " ", RowBox[{"Name", "\[Rule]", " ", "\"\\""}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"{", "\[IndentingNewLine]", RowBox[{ RowBox[{"WidgetFill", "[", "]"}], ",", "\[IndentingNewLine]", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"{", RowBox[{ RowBox[{"\"\\"", "->", "\"\\""}], ",", "\[IndentingNewLine]", RowBox[{"BindEvent", "[", RowBox[{"\"\\"", ",", "\[IndentingNewLine]", RowBox[{"Script", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"result", "=", RowBox[{"formatConversion", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"PropertyValue", "[", RowBox[{"{", RowBox[{"\"\\"", ",", " ", "\"\\""}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"PropertyValue", "[", RowBox[{"{", RowBox[{"\"\\"", ",", " ", "\"\\""}], "}"}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"PropertyValue", "[", RowBox[{"{", RowBox[{"\"\\"", ",", " ", "\"\\""}], "}"}], "]"}]}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"SetPropertyValue", "[", RowBox[{ RowBox[{"{", RowBox[{"\"\\"", ",", " ", "\"\\""}], "}"}], ",", " ", RowBox[{ RowBox[{"PropertyValue", "[", RowBox[{"{", RowBox[{"\"\\"", ",", " ", "\"\\""}], "}"}], "]"}], "<>", "\"\<\\n\>\"", "<>", RowBox[{"ToString", "[", "result", "]"}]}]}], "]"}], ";"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "}"}], ",", " ", RowBox[{"Name", "\[Rule]", "\"\\""}]}], "]"}], ",", "\[IndentingNewLine]", RowBox[{"WidgetFill", "[", "]"}]}], "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", RowBox[{"Widget", "[", RowBox[{"\"\\"", ",", RowBox[{"{", RowBox[{ RowBox[{"\"\\"", "->", "\"\\""}], ",", RowBox[{"\"\\"", "\[Rule]", "5"}], ",", " ", RowBox[{"\"\\"", "\[Rule]", "20"}], ",", RowBox[{"\"\\"", "\[Rule]", "True"}], ",", RowBox[{"\"\\"", "\[Rule]", " ", "False"}]}], "}"}], ",", RowBox[{"Name", "\[Rule]", " ", "\"\\""}]}], "]"}]}], " ", "\[IndentingNewLine]", "}"}], ",", "\[IndentingNewLine]", " ", RowBox[{"Name", " ", "\[Rule]", " ", "\"\\""}]}], "]"}], ",", RowBox[{"IncludedScriptContexts", "\[Rule]", RowBox[{"{", "\"\\"", "}"}]}]}], "\[IndentingNewLine]", "]"}]}], ";"}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"--", "generate"}], " ", "GUI", " ", "input", " ", "dialog", " ", RowBox[{"box", "--"}], RowBox[{"end", "--"}]}], "*)"}], "\[IndentingNewLine]", "\n", RowBox[{"(*", RowBox[{ RowBox[{ RowBox[{"--", "formatConversion"}], " ", "a", " ", "self"}], "-", RowBox[{"defined", " ", RowBox[{"function", ":", " ", RowBox[{"the", " ", "real", " ", RowBox[{"workhorse", "--"}], RowBox[{"begin", "--"}]}]}]}]}], "*)"}]}], "\[IndentingNewLine]", RowBox[{ RowBox[{"formatConversion", "[", RowBox[{"DIRECTORY_", ",", "INPUTFILENAME_", ",", "OUTPUTFILENAME_"}], "]"}], ":=", RowBox[{"(", "\[IndentingNewLine]", RowBox[{ RowBox[{"inputDialogBox", "@", RowBox[{"SetPropertyValue", "[", "\[IndentingNewLine]", RowBox[{ RowBox[{"{", RowBox[{"\"\\"", ",", " ", "\"\\""}], "}"}], ",", "\[IndentingNewLine]", RowBox[{ "\"\\"", "<>", "\"\<\\n\>\"", "\[IndentingNewLine]", "<>", RowBox[{"ToString", "[", " ", RowBox[{"inputDialogBox", "@", RowBox[{"PropertyValue", "[", RowBox[{"{", RowBox[{"\"\\"", ",", " ", "\"\\""}], "}"}], "]"}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}]}], ";", "\[IndentingNewLine]", " ", RowBox[{"(*", " ", RowBox[{ "switch", " ", "to", " ", "current", " ", "directory", " ", "before", " ", "start"}], "*)"}], "\[IndentingNewLine]", RowBox[{"SetDirectory", "[", "DIRECTORY", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "find", " ", "element", " ", "names", " ", "from", " ", "POTCAR"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"FileExistsQ", "[", "\"\\"", "]"}], "\[Equal]", " ", "False"}], ",", " ", RowBox[{"Return", "[", "\"\\"", "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"POTCAR", " ", "=", RowBox[{"Import", "[", RowBox[{"\"\\"", ",", " ", "\"\\""}], "]"}]}], ";", "\n", RowBox[{"(*", RowBox[{"can", " ", "analyze", " ", "20", " ", "elements"}], "*)"}], "\[IndentingNewLine]", RowBox[{ SubscriptBox["element", RowBox[{"total", " ", "number"}]], "=", "0"}], ";", RowBox[{"Array", "[", RowBox[{ SubscriptBox["element", "names"], ",", "20"}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", " ", "=", " ", "1"}], ",", " ", RowBox[{"i", " ", "<=", " ", RowBox[{"Length", "[", "POTCAR", "]"}]}], ",", " ", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"Length", "[", RowBox[{ "POTCAR", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "]"}], "\[Equal]", "0"}], ",", RowBox[{"Continue", "[", "]"}], ",", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"POTCAR", "\[LeftDoubleBracket]", RowBox[{"i", ",", "1"}], "\[RightDoubleBracket]"}], "\[Equal]", "\"\\""}], " ", "||", RowBox[{ RowBox[{"POTCAR", "\[LeftDoubleBracket]", RowBox[{"i", ",", "1"}], "\[RightDoubleBracket]"}], "\[Equal]", "\"\\""}]}], " ", ",", " ", RowBox[{ RowBox[{ SubscriptBox["element", RowBox[{"total", " ", "number"}]], "++"}], ";", RowBox[{ RowBox[{ SubscriptBox["element", "names"], "[", SubscriptBox["element", RowBox[{"total", " ", "number"}]], "]"}], "=", RowBox[{"POTCAR", "\[LeftDoubleBracket]", RowBox[{"i", ",", "2"}], "\[RightDoubleBracket]"}]}]}]}], "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"i", "+=", "500"}], ";"}], "*)"}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Clear", "[", "POTCAR", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"FileExistsQ", "[", "INPUTFILENAME", "]"}], "\[Equal]", " ", "False"}], ",", " ", RowBox[{"Return", "[", RowBox[{"\"\\"", " ", "<>", RowBox[{"ToString", "[", "INPUTFILENAME", "]"}], "<>", "\"\< !\>\""}], "]"}]}], " ", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"read", " ", "in", " ", "POSCAR", " ", "and", " ", "OUTCAR"}], " ", "*)"}], "\n", RowBox[{"POSCAR", " ", "=", " ", RowBox[{"Import", "[", RowBox[{"INPUTFILENAME", ",", " ", "\"\\""}], "]"}]}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"scaleFactor", " ", "=", " ", RowBox[{"POSCAR", "\[LeftDoubleBracket]", RowBox[{"2", ",", " ", "1"}], "\[RightDoubleBracket]"}]}], ";", RowBox[{"(*", RowBox[{"2", "nd", " ", "line"}], "*)"}], "\n", RowBox[{"(*", " ", RowBox[{ RowBox[{"set", " ", "Translational", " ", "vector"}], ",", " ", "Tv", ",", " ", "a", ",", "b", ",", RowBox[{"c", " ", "->", " ", "x"}], ",", "y", ",", "z"}], " ", "*)"}], "\n", RowBox[{"(*", " ", RowBox[{ RowBox[{"cut", " ", "off", " ", "any", " ", "comment"}], ",", " ", RowBox[{ "only", " ", "take", " ", "the", " ", "first", " ", "three", " ", "elements", " ", "of", " ", "the", " ", "row"}]}], "*)"}], "\n", RowBox[{ SubscriptBox["Tv", "a"], " ", "=", " ", RowBox[{ RowBox[{ "POSCAR", "\[LeftDoubleBracket]", "3", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", RowBox[{"1", " ", ";;", " ", "3"}], "\[RightDoubleBracket]"}]}], ";", RowBox[{ SubscriptBox["Tv", "b"], " ", "=", " ", RowBox[{ RowBox[{ "POSCAR", "\[LeftDoubleBracket]", "4", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", RowBox[{"1", " ", ";;", " ", "3"}], "\[RightDoubleBracket]"}]}], ";", RowBox[{ SubscriptBox["Tv", "c"], " ", "=", " ", RowBox[{ RowBox[{ "POSCAR", "\[LeftDoubleBracket]", "5", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", RowBox[{"1", " ", ";;", " ", "3"}], "\[RightDoubleBracket]"}]}], ";", "\n", RowBox[{"TvMatrix", " ", "=", " ", RowBox[{"MatrixForm", "[", RowBox[{"{", RowBox[{ SubscriptBox["Tv", "a"], ",", " ", SubscriptBox["Tv", "b"], ",", " ", SubscriptBox["Tv", "c"]}], "}"}], "]"}]}], ";", "\n", RowBox[{"xyzTvMatrix", " ", "=", " ", RowBox[{"scaleFactor", "*", RowBox[{ "TvMatrix", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}]}]}], ";", "\[IndentingNewLine]", "\n", RowBox[{"(*", " ", RowBox[{"check", " ", "type", " ", "of", " ", "coordinate"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"If", " ", "[", RowBox[{ RowBox[{ RowBox[{ RowBox[{"ToLowerCase", "[", RowBox[{ RowBox[{"Characters", "[", RowBox[{"POSCAR", "\[LeftDoubleBracket]", RowBox[{"8", ",", " ", "1"}], "\[RightDoubleBracket]"}], "]"}], "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "]"}], " ", "!=", " ", "\"\\""}], " ", "&&", " ", RowBox[{ RowBox[{"ToLowerCase", "[", RowBox[{ RowBox[{"Characters", "[", RowBox[{"POSCAR", "\[LeftDoubleBracket]", RowBox[{"7", ",", " ", "1"}], "\[RightDoubleBracket]"}], "]"}], "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "]"}], " ", "!=", " ", "\"\\""}]}], " ", ",", " ", RowBox[{"(*", RowBox[{ RowBox[{ "Print", "[", "\"\\"", "]"}], ";"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"coordType", "=", "\"\\""}], ",", RowBox[{"coordType", "=", "\"\\""}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{ "check", " ", "selective", " ", "dynamics", " ", "and", " ", "decide", " ", "coord", " ", "starting", " ", "line"}], " ", "*)"}], "\n", RowBox[{"If", " ", "[", RowBox[{ RowBox[{ RowBox[{"ToLowerCase", "[", RowBox[{ RowBox[{"Characters", "[", RowBox[{"POSCAR", "\[LeftDoubleBracket]", RowBox[{"7", ",", " ", "1"}], "\[RightDoubleBracket]"}], "]"}], "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "]"}], " ", "!=", " ", "\"\\""}], " ", ",", " ", RowBox[{ RowBox[{"Print", "[", "\"\\"", "]"}], ";", " ", "\[IndentingNewLine]", RowBox[{"coordStartingLine", "=", "8"}]}], ",", RowBox[{"coordStartingLine", "=", "9"}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", " ", RowBox[{"(*", RowBox[{"cut", " ", "off", " ", "the", " ", RowBox[{"comments", " ", "!"}], " ", "in", " ", "the", " ", "atom", " ", "number", " ", RowBox[{"line", "."}]}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{ SubscriptBox["atom", "Numbers"], "=", RowBox[{ "POSCAR", "\[LeftDoubleBracket]", "6", "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", RowBox[{"atomNum", "=", "0"}], ";", RowBox[{"commentPosition", "=", RowBox[{"{", "}"}]}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"elementNum", " ", "=", " ", "1"}], ",", " ", RowBox[{"elementNum", " ", "<=", " ", RowBox[{"Length", "[", SubscriptBox["atom", "Numbers"], "]"}]}], ",", " ", RowBox[{"elementNum", "++"}], ",", "\n", RowBox[{ RowBox[{"commentPosition", "=", RowBox[{"StringPosition", "[", RowBox[{ RowBox[{"ToString", "[", RowBox[{ SubscriptBox["atom", "Numbers"], "\[LeftDoubleBracket]", "elementNum", " ", "\[RightDoubleBracket]"}], "]"}], ",", "\"\\""}], "]"}]}], ";", "\n", " ", RowBox[{"If", "[", RowBox[{ RowBox[{"commentPosition", "\[NotEqual]", " ", RowBox[{"{", "}"}]}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"commentPosition", "\[LeftDoubleBracket]", RowBox[{"1", ",", "1"}], "\[RightDoubleBracket]"}], "\[NotEqual]", "1"}], ",", "\[IndentingNewLine]", RowBox[{ RowBox[{ RowBox[{"numOfElement", "[", "elementNum", "]"}], " ", "=", RowBox[{"ToExpression", "[", RowBox[{"StringTake", "[", RowBox[{ RowBox[{"ToString", "[", RowBox[{ SubscriptBox["atom", "Numbers"], "\[LeftDoubleBracket]", "elementNum", " ", "\[RightDoubleBracket]"}], "]"}], ",", RowBox[{ RowBox[{"commentPosition", "\[LeftDoubleBracket]", RowBox[{"1", ",", "1"}], "\[RightDoubleBracket]"}], "-", "1"}]}], "]"}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"atomNum", "+=", RowBox[{"numOfElement", "[", "elementNum", "]"}]}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{"Print", "[", RowBox[{ RowBox[{ SubscriptBox["atom", "Numbers"], "\[LeftDoubleBracket]", "elementNum", " ", "\[RightDoubleBracket]"}], ",", "\"\< ! at \>\"", ",", RowBox[{"commentPosition", "\[LeftDoubleBracket]", RowBox[{"1", ",", "1"}], "\[RightDoubleBracket]"}], ",", " ", "\"\< place\>\""}], "]"}], ";"}], "*)"}], "\[IndentingNewLine]", RowBox[{"Break", "[", "]"}]}], ",", "\[IndentingNewLine]", " ", RowBox[{ RowBox[{ RowBox[{"numOfElement", "[", "elementNum", "]"}], " ", "=", " ", RowBox[{ SubscriptBox["atom", "Numbers"], "\[LeftDoubleBracket]", "elementNum", "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", RowBox[{"atomNum", "+=", " ", RowBox[{"numOfElement", "[", "elementNum", "]"}]}]}]}], "\[IndentingNewLine]", "]"}]}]}], " ", RowBox[{"(*", RowBox[{ RowBox[{"end", " ", "If", " ", "commentPosition"}], "\[NotEqual]", " ", RowBox[{"{", "}"}]}], "*)"}], "\[IndentingNewLine]", "]"}], ";", " ", RowBox[{"(*", RowBox[{"end", " ", "elementNum", " ", "loop"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"elementNum", "-", "1"}], "\[NotEqual]", " ", SubscriptBox["element", RowBox[{"total", " ", "number"}]]}], ",", " ", RowBox[{ RowBox[{"msg1", "=", RowBox[{ "\"\\"", "<>", " ", RowBox[{"ToString", "[", "INPUTFILENAME", "]"}], "<>", "\"\< specifies \>\"", "<>", RowBox[{"ToString", "[", RowBox[{"elementNum", "-", "1"}], "]"}], "<>", "\"\< element(s).\\n\>\"", "<>", " ", "\"\\"", "<>", RowBox[{"ToString", "[", " ", SubscriptBox["element", RowBox[{"total", " ", "number"}]], "]"}], "<>", "\"\< element(s):\>\""}]}], ";", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"i", " ", "=", " ", "1"}], ",", " ", RowBox[{"i", " ", "<=", " ", SubscriptBox["element", RowBox[{"total", " ", "number"}]]}], ",", " ", RowBox[{"i", "++"}], ",", RowBox[{"elementsFound", "=", RowBox[{"elementsFound", "<>", "\"\<\\n\>\"", "<>", RowBox[{"ToString", "[", RowBox[{ SubscriptBox["element", "names"], "[", "i", "]"}], "]"}]}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", RowBox[{"msg", "<>", "\"\<\\n\>\"", "<>", "elementsFound"}], "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", "\n", RowBox[{"(*", RowBox[{ "check", " ", "the", " ", "line", " ", "number", " ", "of", " ", "coord"}], "*)"}], "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"coordNum", " ", "=", " ", "coordStartingLine"}], ",", " ", RowBox[{"coordNum", " ", "<=", " ", RowBox[{"Length", "[", "POSCAR", "]"}]}], ",", " ", RowBox[{"coordNum", "++"}], ",", "\n", " ", RowBox[{ RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{ "POSCAR", "\[LeftDoubleBracket]", "coordNum", " ", "\[RightDoubleBracket]"}], "\[Equal]", RowBox[{"{", "}"}]}], ",", RowBox[{ RowBox[{ SubscriptBox["coord", "lines"], "=", RowBox[{"coordNum", "-", "coordStartingLine"}]}], ";", RowBox[{"Break", "[", "]"}]}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{"coordNum", " ", "\[Equal]", RowBox[{"Length", "[", "POSCAR", "]"}]}], ",", RowBox[{ RowBox[{ SubscriptBox["coord", "lines"], "=", RowBox[{"coordNum", "-", "coordStartingLine", "+", "1"}]}], ";", RowBox[{"Break", "[", "]"}]}]}], "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", RowBox[{"(*", RowBox[{"only", " ", RowBox[{"break", "/", "jump"}], " ", "out", " ", "of", " ", "this", " ", "For", " ", "loop"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ "check", " ", "if", " ", "the", " ", "line", " ", "number", " ", "of", " ", "coord"}], " ", "\[Equal]", " ", RowBox[{"number", " ", "of", " ", "atoms"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"If", "[", " ", RowBox[{ RowBox[{ SubscriptBox["coord", "lines"], "\[NotEqual]", " ", "atomNum"}], ",", " ", "\[IndentingNewLine]", RowBox[{ RowBox[{"msg1", "=", RowBox[{ "\"\\"", "<>", "\"\\"", "<>", RowBox[{"ToString", "[", " ", "atomNum", "]"}], "<>", "\"\<; Line of \>\"", "<>", RowBox[{"ToString", "[", "coordType", "]"}], "<>", "\"\< coord = \>\"", "<>", RowBox[{"ToString", "[", " ", SubscriptBox["coord", "lines"], "]"}]}]}], ";", "\[IndentingNewLine]", RowBox[{"Return", "[", "msg1", "]"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "keep", " ", "one", " ", "row", " ", "output", " ", "in", " ", "one", " ", "line"}], " ", "*)"}], "\[IndentingNewLine]", RowBox[{"resultFile", " ", "=", " ", RowBox[{"OUTPUTFILENAME", " ", "<>", " ", "\"\<.com\>\""}]}], ";", "\n", " ", RowBox[{"results", " ", "=", " ", RowBox[{"OpenWrite", "[", RowBox[{"resultFile", ",", " ", RowBox[{"FormatType", " ", "\[Rule]", " ", "OutputForm"}], ",", " ", RowBox[{"PageWidth", " ", "\[Rule]", " ", "300"}]}], "]"}]}], ";", "\n", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ RowBox[{ "write", " ", "title", " ", "part", " ", "for", " ", "gaussian", " ", "file", " ", "format"}], ";", " ", RowBox[{"can", " ", "be", " ", "changed", " ", "accordingly"}]}], " ", "*)"}], "\[IndentingNewLine]", " ", RowBox[{"Write", "[", RowBox[{ "results", ",", " ", "\"\<%chk=input.chk\\n# pbepbe/3-21g/auto\\n\>\""}], " ", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Write", "[", RowBox[{"results", ",", " ", RowBox[{"TableForm", "[", RowBox[{ RowBox[{ "POSCAR", "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], ",", RowBox[{"TableSpacing", "\[Rule]", " ", RowBox[{"{", RowBox[{"2.", ",", "0."}], "}"}]}], ",", RowBox[{"TableDirections", "\[Rule]", "Row"}]}], "]"}]}], " ", "]"}], ";", "\[IndentingNewLine]", RowBox[{"Write", "[", RowBox[{"results", ",", " ", "\"\<\\n0 1\>\""}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"(*", " ", RowBox[{"initialization", " ", ",", " ", RowBox[{ "nP", " ", "and", " ", "nD", " ", "are", " ", "output", " ", "precision", " ", "digit", " ", "number"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"totalNumOfElement", " ", "=", " ", "0"}], ";", " ", RowBox[{"nP", " ", "=", " ", "12"}], ";", " ", RowBox[{"nD", " ", "=", " ", "8"}], ";", " ", "\[IndentingNewLine]", RowBox[{"(*", RowBox[{ "enumerate", " ", "all", " ", "the", " ", "elements", " ", "listed", " ", "in", " ", "vasp", " ", "files"}], "*)"}], "\[IndentingNewLine]", "\[IndentingNewLine]", RowBox[{"For", "[", RowBox[{ RowBox[{"elementNum", " ", "=", " ", "1"}], ",", " ", RowBox[{"elementNum", " ", "<=", " ", SubscriptBox["element", RowBox[{"total", " ", "number"}]]}], ",", " ", RowBox[{"elementNum", "++"}], ",", "\n", "\[IndentingNewLine]", RowBox[{ RowBox[{"For", "[", RowBox[{ RowBox[{"i", " ", "=", " ", RowBox[{"coordStartingLine", " ", "+", " ", "totalNumOfElement"}]}], ",", RowBox[{"i", " ", "<", " ", RowBox[{ RowBox[{"numOfElement", "[", "elementNum", "]"}], " ", "+", " ", "coordStartingLine", " ", "+", " ", "totalNumOfElement"}]}], ",", " ", RowBox[{"i", "++"}], ",", "\[IndentingNewLine]", " ", RowBox[{"(*", " ", RowBox[{ RowBox[{"read", " ", "in", " ", "abc"}], "-", RowBox[{ "coord", " ", "and", " ", "convert", " ", "it", " ", "to", " ", "cartesian", " ", "coord", " ", "if", " ", "necessary"}]}], "*)"}], " ", RowBox[{ RowBox[{"abcCoord", " ", "=", " ", RowBox[{ RowBox[{ "POSCAR", "\[LeftDoubleBracket]", "i", "\[RightDoubleBracket]"}], "\[LeftDoubleBracket]", RowBox[{"1", " ", ";;", " ", "3"}], "\[RightDoubleBracket]"}]}], ";", "\[IndentingNewLine]", RowBox[{"If", "[", RowBox[{ RowBox[{ RowBox[{"ToLowerCase", "[", RowBox[{ RowBox[{"Characters", "[", "coordType", "]"}], "\[LeftDoubleBracket]", "1", "\[RightDoubleBracket]"}], "]"}], " ", "\[Equal]", " ", "\"\\""}], ",", " ", RowBox[{"xyzCoord", "=", "abcCoord"}], ",", " ", RowBox[{"xyzCoord", " ", "=", " ", RowBox[{"abcCoord", ".", "xyzTvMatrix"}]}]}], "\[IndentingNewLine]", "]"}], ";", "\[IndentingNewLine]", "\[IndentingNewLine]", " ", RowBox[{"(*", RowBox[{ RowBox[{"Print", "[", RowBox[{ RowBox[{"i", "-", "8"}], ",", "xyzCoord"}], "]"}], ";"}], "*)"}], " ", "\[IndentingNewLine]", RowBox[{"Write", "[", RowBox[{"results", ",", " ", RowBox[{"NumberForm", "[", RowBox[{ RowBox[{"Chop", "[", RowBox[{"TableForm", "[", RowBox[{ RowBox[{"Join", "[", " ", RowBox[{ RowBox[{"{", RowBox[{ SubscriptBox["element", "names"], "[", "elementNum", "]"}], "}"}], ",", "xyzCoord"}], "]"}], " ", ",", " ", RowBox[{"TableSpacing", "\[Rule]", " ", RowBox[{"{", RowBox[{"2.", ",", "0."}], "}"}]}], ",", RowBox[{"TableDirections", "\[Rule]", "Row"}]}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"nP", ",", "nD"}], "}"}]}], "]"}]}], "]"}], ";"}]}], "\[IndentingNewLine]", " ", "]"}], ";", RowBox[{"(*", RowBox[{"end", " ", "of", " ", "i", " ", "loop"}], "*)"}], "\[IndentingNewLine]", " ", RowBox[{"totalNumOfElement", " ", "+=", " ", RowBox[{"numOfElement", "[", "elementNum", "]"}]}]}]}], " ", "\[IndentingNewLine]", " ", "]"}], ";", RowBox[{"(*", RowBox[{"end", " ", "of", " ", "element", " ", "loop"}], "*)"}], "\[IndentingNewLine]", "\n", RowBox[{"(*", RowBox[{ RowBox[{ "write", " ", "the", " ", "PBC", " ", "part", " ", "of", " ", "gaussian", " ", "files"}], ",", " ", RowBox[{"translational", " ", "vectors"}]}], "*)"}], "\[IndentingNewLine]", RowBox[{"TvName", "=", RowBox[{"Array", "[", RowBox[{ RowBox[{ RowBox[{"{", "\"\\"", "}"}], "&"}], ",", RowBox[{"Length", "[", "xyzTvMatrix", "]"}]}], "]"}]}], ";", "\[IndentingNewLine]", RowBox[{"Write", "[", RowBox[{"results", ",", " ", RowBox[{"NumberForm", "[", RowBox[{ RowBox[{"Chop", "[", RowBox[{"TableForm", "[", RowBox[{ RowBox[{"Join", "[", RowBox[{"TvName", ",", "xyzTvMatrix", ",", "2"}], "]"}], " ", ",", " ", RowBox[{"TableSpacing", "\[Rule]", " ", RowBox[{"{", RowBox[{"0.", ",", "2."}], "}"}]}]}], "]"}], "]"}], ",", RowBox[{"{", RowBox[{"nP", ",", "nD"}], "}"}]}], "]"}]}], "]"}], ";", "\[IndentingNewLine]", RowBox[{"Close", "[", "resultFile", "]"}], ";", "\[IndentingNewLine]", RowBox[{ "Return", "[", "\"\\"", "]"}], ";"}], "\n", ")"}]}], "\[IndentingNewLine]"}], "Input"] }, Closed]], Cell[CellGroupData[{ Cell["P.S. ", "Section", FontColor->GrayLevel[0.85]], Cell["\<\ 1. Need a better GUI 2. Variables names are not very self-explanatory and confusing. 3. The entire script is not well written.\ \>", "Text", FontColor->RGBColor[0., 0.6666666666666666, 0.]] }, Closed]] }, Open ]] }, WindowToolbars->"EditBar", WindowSize->{918, 978}, WindowMargins->{{53, Automatic}, {-197, Automatic}}, TrackCellChangeTimes->False, Magnification->1.5, FrontEndVersion->"7.0 for Linux x86 (64-bit) (November 11, 2008)", StyleDefinitions->"Default.nb" ] (* End of Notebook Content *) (* Internal cache information *) (*CellTagsOutline CellTagsIndex->{} *) (*CellTagsIndex CellTagsIndex->{} *) (*NotebookFileOutline Notebook[{ Cell[CellGroupData[{ Cell[567, 22, 82, 2, 126, "Title"], Cell[CellGroupData[{ Cell[674, 28, 58, 1, 108, "Section"], Cell[735, 31, 220, 7, 109, "Text"], Cell[CellGroupData[{ Cell[980, 42, 38, 0, 63, "Subsubsection"], Cell[1021, 44, 217, 5, 148, "Text"] }, Closed]], Cell[CellGroupData[{ Cell[1275, 54, 42, 0, 46, "Subsubsection"], Cell[1320, 56, 441, 8, 232, "Text"] }, Closed]] }, Closed]], Cell[CellGroupData[{ Cell[1810, 70, 50, 0, 61, "Section"], Cell[1863, 72, 36094, 831, 8395, "Input"] }, Closed]], Cell[CellGroupData[{ Cell[37994, 908, 53, 1, 61, "Section"], Cell[38050, 911, 212, 5, 148, "Text"] }, Closed]] }, Open ]] } ] *) (* End of internal cache information *)