35{
36 if (argc < 3)
37 {
38 cout << "USAGE: " << argv[0] << " <format> <elem1 <elem2 ...>>\n"
39 << " <format> ... Structure file output format "
40 "(xyz/poscar).\n"
41 << " <elemN> .... Symbol for Nth element.\n"
42 << " Execute in directory with these NNP files present:\n"
43 << " - input.data (structure file)\n";
44 return 1;
45 }
46
48 logFile.open(
"nnp-convert.log");
51
52 log << "\n";
53 log << "*** NNP-CONVERT *************************"
54 "**************************************\n";
55 log << "\n";
56
57 string format = argv[1];
58 log <<
strpr(
"Requested file format : %s\n", format.c_str());
59 string outputFileName;
60 string outputFileNamePrefix;
61 if (format == "xyz")
62 {
63 outputFileName = "input.xyz";
64 log <<
strpr(
"Output file name : %s\n", outputFileName.c_str());
65 }
66 else if (format == "poscar")
67 {
68 outputFileNamePrefix = "POSCAR";
69 log <<
strpr(
"Output file name prefix: %s\n",
70 outputFileNamePrefix.c_str());
71 }
72 else
73 {
74 log << "ERROR: Unknown output file format.\n";
75 return 1;
76 }
77 size_t numElements = argc - 2;
78 log <<
strpr(
"Number of elements : %zu\n", numElements);
79 string elements;
80 elements += argv[2];
81 for (size_t i = 3; i < numElements + 2; ++i)
82 {
83 elements += " ";
84 elements += argv[i];
85 }
86 log <<
strpr(
"Element string : %s\n", elements.c_str());
87 log << "*****************************************"
88 "**************************************\n";
89
92
93 ifstream inputFile;
94 inputFile.open("input.data");
97
98 size_t countStructures = 0;
99 ofstream outputFile;
100 if (format == "xyz")
101 {
102 outputFile.open(outputFileName.c_str());
103 }
104
105 while (inputFile.peek() != EOF)
106 {
108 if (format == "xyz")
109 {
111 }
112 else if (format == "poscar")
113 {
114 outputFileName =
strpr(
"%s_%d",
115 outputFileNamePrefix.c_str(),
116 countStructures + 1);
117 outputFile.open(outputFileName.c_str());
119 outputFile.close();
120 }
121 countStructures++;
122 log <<
strpr(
"Configuration %7zu: %7zu atoms\n",
123 countStructures,
126 }
127
128 if (format == "xyz")
129 {
130 outputFile.close();
131 }
132
133 log << "*****************************************"
134 "**************************************\n";
136
137 return 0;
138}
std::size_t registerElements(std::string const &elementLine)
Extract all elements and store in element map.
Logging class for library output.
void registerStreamPointer(std::ofstream *const &streamPointer)
Register new C++ ofstream pointer.
string strpr(const char *format,...)
String version of printf function.
Storage for one atomic configuration.
void setElementMap(ElementMap const &elementMap)
Set element map of structure.
void writeToFilePoscar(std::ofstream *const &file) const
Write configuration to POSCAR file.
void writeToFileXyz(std::ofstream *const &file) const
Write configuration to xyz file.
void readFromFile(std::string const fileName="input.data")
Read configuration from file.
void reset()
Reset everything but elementMap.
std::size_t numAtoms
Total number of atoms present in this structure.