// Load Species information from XYZ file bool Species::loadFromXYZ(const char* filename) { Messenger::print("Loading XYZ data from file '%s'\n", filename); // Open the specified file... LineParser parser; parser.openInput(filename); if (!parser.isFileGoodForReading()) { Messenger::error("Couldn't open XYZ file '%s'.\n", filename); return false; } // Clear any existing data clear(); // Simple format - first line is number of atoms, next line is title, then follow atoms/coordinates, one atom per line parser.getArgsDelim(LineParser::Defaults); int nAtoms = parser.argi(0); parser.readNextLine(LineParser::Defaults); name_ = parser.line(); int el, success; for (int n=0; n<nAtoms; ++n) { success = parser.getArgsDelim(LineParser::Defaults); if (success != 0) { parser.closeFiles(); Messenger::error("Couldn't read Atom %i from file '%s'\n", n+1, filename); return false; } el = PeriodicTable::find(parser.argc(0)); if (el == -1) el = 0; SpeciesAtom* i = addAtom(el, parser.argd(1), parser.argd(2),parser.argd(3)); if (parser.hasArg(4)) i->setCharge(parser.argd(4)); } Messenger::print("Succesfully loaded XYZ data from file '%s'.\n", filename); parser.closeFiles(); return true; }
// Parse Simulation block bool SimulationBlock::parse(LineParser& parser, DUQ* duq) { Messenger::print("\nParsing %s block...\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock)); bool blockDone = false, error = false; while (!parser.eofOrBlank(duq->worldPool())) { // Read in a line, which should contain a keyword and a minimum number of arguments parser.getArgsDelim(duq->worldPool(), LineParser::SkipBlanks+LineParser::UseQuotes); SimulationBlock::SimulationKeyword simKeyword = SimulationBlock::keyword(parser.argc(0)); if ((simKeyword != SimulationBlock::nSimulationKeywords) && ((parser.nArgs()-1) < SimulationBlock::nArguments(simKeyword))) { Messenger::error("Not enough arguments given to '%s' keyword.\n", SimulationBlock::keyword(simKeyword)); error = true; break; } switch (simKeyword) { case (SimulationBlock::BoxNormalisationPointsKeyword): duq->setBoxNormalisationPoints(parser.argi(1)); break; case (SimulationBlock::EndSimulationKeyword): Messenger::print("Found end of %s block.\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock)); blockDone = true; break; case (SimulationBlock::MaxIterationsKeyword): duq->setMaxIterations(parser.argi(1)); break; case (SimulationBlock::ParallelStrategyKeyword): if (DUQ::parallelStrategy(parser.argc(1)) == DUQ::nParallelStrategies) { Messenger::error("Unrecognised parallel strategy '%s'.\n", parser.argc(1)); error = true; } else duq->setParallelStrategy(DUQ::parallelStrategy(parser.argc(1))); break; case (SimulationBlock::SeedKeyword): duq->setSeed(parser.argi(1)); break; case (SimulationBlock::WindowFunctionKeyword): if (Data2D::windowFunction(parser.argc(1)) == Data2D::nWindowFunctions) { Messenger::error("Unrecognised window function '%s'.\n", parser.argc(1)); error = true; } else duq->setWindowFunction(Data2D::windowFunction(parser.argc(1))); break; case (SimulationBlock::nSimulationKeywords): Messenger::print("Unrecognised %s block keyword found - '%s'\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock), parser.argc(0)); InputBlocks::printValidKeywords(InputBlocks::SimulationBlock); error = true; break; default: printf("DEV_OOPS - %s block keyword '%s' not accounted for.\n", InputBlocks::inputBlock(InputBlocks::SimulationBlock), SimulationBlock::keyword(simKeyword)); error = true; break; } // Error encountered? if (error) break; // End of block? if (blockDone) break; } return (!error); }