Changeset 032f31
- Timestamp:
- Oct 17, 2011, 4:56:37 PM (13 years ago)
- Branches:
- Action_Thermostats, Add_AtomRandomPerturbation, Add_FitFragmentPartialChargesAction, Add_RotateAroundBondAction, Add_SelectAtomByNameAction, Added_ParseSaveFragmentResults, AddingActions_SaveParseParticleParameters, Adding_Graph_to_ChangeBondActions, Adding_MD_integration_tests, Adding_ParticleName_to_Atom, Adding_StructOpt_integration_tests, AtomFragments, Automaking_mpqc_open, AutomationFragmentation_failures, Candidate_v1.5.4, Candidate_v1.6.0, Candidate_v1.6.1, ChangeBugEmailaddress, ChangingTestPorts, ChemicalSpaceEvaluator, CombiningParticlePotentialParsing, Combining_Subpackages, Debian_Package_split, Debian_package_split_molecuildergui_only, Disabling_MemDebug, Docu_Python_wait, EmpiricalPotential_contain_HomologyGraph, EmpiricalPotential_contain_HomologyGraph_documentation, Enable_parallel_make_install, Enhance_userguide, Enhanced_StructuralOptimization, Enhanced_StructuralOptimization_continued, Example_ManyWaysToTranslateAtom, Exclude_Hydrogens_annealWithBondGraph, FitPartialCharges_GlobalError, Fix_BoundInBox_CenterInBox_MoleculeActions, Fix_ChargeSampling_PBC, Fix_ChronosMutex, Fix_FitPartialCharges, Fix_FitPotential_needs_atomicnumbers, Fix_ForceAnnealing, Fix_IndependentFragmentGrids, Fix_ParseParticles, Fix_ParseParticles_split_forward_backward_Actions, Fix_PopActions, Fix_QtFragmentList_sorted_selection, Fix_Restrictedkeyset_FragmentMolecule, Fix_StatusMsg, Fix_StepWorldTime_single_argument, Fix_Verbose_Codepatterns, Fix_fitting_potentials, Fixes, ForceAnnealing_goodresults, ForceAnnealing_oldresults, ForceAnnealing_tocheck, ForceAnnealing_with_BondGraph, ForceAnnealing_with_BondGraph_continued, ForceAnnealing_with_BondGraph_continued_betteresults, ForceAnnealing_with_BondGraph_contraction-expansion, FragmentAction_writes_AtomFragments, FragmentMolecule_checks_bonddegrees, GeometryObjects, Gui_Fixes, Gui_displays_atomic_force_velocity, ImplicitCharges, IndependentFragmentGrids, IndependentFragmentGrids_IndividualZeroInstances, IndependentFragmentGrids_IntegrationTest, IndependentFragmentGrids_Sole_NN_Calculation, JobMarket_RobustOnKillsSegFaults, JobMarket_StableWorkerPool, JobMarket_unresolvable_hostname_fix, MoreRobust_FragmentAutomation, ODR_violation_mpqc_open, PartialCharges_OrthogonalSummation, PdbParser_setsAtomName, PythonUI_with_named_parameters, QtGui_reactivate_TimeChanged_changes, Recreated_GuiChecks, Rewrite_FitPartialCharges, RotateToPrincipalAxisSystem_UndoRedo, SaturateAtoms_findBestMatching, SaturateAtoms_singleDegree, StoppableMakroAction, Subpackage_CodePatterns, Subpackage_JobMarket, Subpackage_LinearAlgebra, Subpackage_levmar, Subpackage_mpqc_open, Subpackage_vmg, Switchable_LogView, ThirdParty_MPQC_rebuilt_buildsystem, TrajectoryDependenant_MaxOrder, TremoloParser_IncreasedPrecision, TremoloParser_MultipleTimesteps, TremoloParser_setsAtomName, Ubuntu_1604_changes, stable
- Children:
- a67cf0
- Parents:
- 7f570c
- git-author:
- Frederik Heber <heber@…> (10/06/11 11:15:56)
- git-committer:
- Frederik Heber <heber@…> (10/17/11 16:56:37)
- Location:
- src/Parser
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
src/Parser/Psi3Parser.cpp
r7f570c r032f31 64 64 void FormatParser< psi3 >::load(istream *file) 65 65 { 66 // bool Psi3Section = false; 67 // bool MoleculeSection = false; 68 // bool GeometrySection = false; 69 // bool BasisSection = false; 70 // bool AuxBasisSection = false; 71 // char line[MAXSTRINGSIZE]; 72 // typedef boost::tokenizer<boost::char_separator<char> > tokenizer; 73 // boost::char_separator<char> sep("[]"); 74 // boost::char_separator<char> angularsep("<>"); 75 // boost::char_separator<char> equalitysep(" ="); 76 // boost::char_separator<char> whitesep(" \t"); 77 // ConvertTo<double> toDouble; 78 // 79 // molecule *newmol = World::getInstance().createMolecule(); 80 // newmol->ActiveFlag = true; 81 // // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include 82 // World::getInstance().getMolecules()->insert(newmol); 83 // while (file->good()) { 84 // file->getline(line, MAXSTRINGSIZE-1); 85 // std::string linestring(line); 86 // if ((linestring.find("atoms geometry") == string::npos) && (linestring.find("}") != string::npos)) { 87 // GeometrySection = false; 88 // } 89 // if ((linestring.find(")") != string::npos)) { // ends a section which do not overlap 90 // Psi3Section = false; 91 // MoleculeSection = false; 92 // BasisSection = false; 93 // AuxBasisSection = false; 94 // } 95 // if (MoleculeSection) { 96 // if (GeometrySection) { // we have an atom 97 // tokenizer tokens(linestring, sep); 98 // // if (tokens.size() != 2) 99 // // throw Psi3ParseException; 100 // tokenizer::iterator tok_iter = tokens.begin(); 101 // ASSERT(tok_iter != tokens.end(), 102 // "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!"); 103 // std::stringstream whitespacefilter(*tok_iter++); 104 // std::string element; 105 // whitespacefilter >> ws >> element; 106 // ASSERT(tok_iter != tokens.end(), 107 // "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!"); 108 // std::string vector = *tok_iter; 109 // tokenizer vectorcomponents(vector, whitesep); 110 // Vector X; 111 // // if (vectorcomponents.size() != NDIM) 112 // // throw Psi3ParseException; 113 // tok_iter = vectorcomponents.begin(); 114 // for (int i=0; i<NDIM; ++i) { 115 // X[i] = toDouble(*tok_iter++); 116 // } 117 // // create atom 118 // atom *newAtom = World::getInstance().createAtom(); 119 // newAtom->setType(World::getInstance().getPeriode()->FindElement(element)); 120 // newAtom->setPosition(X); 121 // newmol->AddAtom(newAtom); 122 // DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl); 123 // } 124 // } 125 // if (Psi3Section) { 126 // if (linestring.find("mole<") != string::npos) { // get theory 127 // tokenizer tokens(linestring, angularsep); 128 // tokenizer::iterator tok_iter = tokens.begin(); 129 // ++tok_iter; 130 // ASSERT(tok_iter != tokens.end(), 131 // "FormatParser< psi3 >::load() - missing token in brackets<> for mole< in line "+linestring+"!"); 132 // std::string value(*tok_iter); 133 // std::stringstream linestream("theory = "+value); 134 // linestream >> getParams(); 135 // } else if (linestring.find("integrals<") != string::npos) { // get theory 136 // tokenizer tokens(linestring, angularsep); 137 // tokenizer::iterator tok_iter = tokens.begin(); 138 // ++tok_iter; 139 // ASSERT(tok_iter != tokens.end(), 140 // "FormatParser< psi3 >::load() - missing token in brackets<> for integrals< in line "+linestring+"!"); 141 // std::string value(*tok_iter); 142 // std::stringstream linestream("integration = "+value); 143 // linestream >> getParams(); 144 // } else if ((linestring.find("molecule") == string::npos) && (linestring.find("basis") == string::npos)){ 145 // // molecule and basis must not be parsed in this section 146 // tokenizer tokens(linestring, equalitysep); 147 // tokenizer::iterator tok_iter = tokens.begin(); 148 // ASSERT(tok_iter != tokens.end(), 149 // "FormatParser< psi3 >::load() - missing token before '=' for Psi3Section in line "+linestring+"!"); 150 // std::stringstream whitespacefilter(*tok_iter); 151 // std::string key; 152 // whitespacefilter >> ws >> key; 153 // if (getParams().haveParameter(key)) { 154 // std::stringstream linestream(linestring); 155 // linestream >> getParams(); 156 // } else { // unknown keys are simply ignored as long as parser is incomplete 157 // DoLog(2) && (Log() << Verbose(2) << "INFO: '"+key+"' is unknown and ignored." << std::endl); 158 // } 159 // } 160 // } 161 // if (BasisSection) { 162 // tokenizer tokens(linestring, equalitysep); 163 // tokenizer::iterator tok_iter = tokens.begin(); 164 // ASSERT(tok_iter != tokens.end(), 165 // "FormatParser< psi3 >::load() - missing token for BasisSection in line "+linestring+"!"); 166 // std::string key(*tok_iter++); 167 // ASSERT(tok_iter != tokens.end(), 168 // "FormatParser< psi3 >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!"); 169 // std::string value(*tok_iter); 170 // tok_iter++; 171 // // TODO: use exception instead of ASSERT 172 // ASSERT(tok_iter == tokens.end(), 173 // "FormatParser< psi3 >::load() - more than (key = value) on line "+linestring+"."); 174 // if (key == "name") { 175 // std::stringstream linestream("basis = "+value); 176 // linestream >> getParams(); 177 // } 178 // } 179 // if (AuxBasisSection) { 180 // tokenizer tokens(linestring, equalitysep); 181 // tokenizer::iterator tok_iter = tokens.begin(); 182 // ASSERT(tok_iter != tokens.end(), 183 // "FormatParser< psi3 >::load() - missing token for AuxBasisSection in line "+linestring+"!"); 184 // std::string key(*tok_iter++); 185 // ASSERT(tok_iter != tokens.end(), 186 // "FormatParser< psi3 >::load() - missing value for BasisSection after key "+key+" in line "+linestring+"!"); 187 // std::string value(*tok_iter); 188 // tok_iter++; 189 // // TODO: use exception instead of ASSERT 190 // ASSERT(tok_iter == tokens.end(), 191 // "FormatParser< psi3 >::load() - more than (key = value) on line "+linestring+"."); 192 // if (key == "name") { 193 // std::stringstream linestream("aux_basis = "+value); 194 // linestream >> getParams(); 195 // } 196 // } 197 // // set some scan flags 198 // if (linestring.find("psi3:") != string::npos) { 199 // Psi3Section = true; 200 // } 201 // if (linestring.find("molecule<Molecule>:") != string::npos) { 202 // MoleculeSection = true; 203 // } 204 // if (linestring.find("atoms geometry") != string::npos) { 205 // GeometrySection = true; 206 // } 207 // if ((linestring.find("basis<GaussianBasisSet>:") != string::npos) && ((linestring.find("abasis<") == string::npos))) { 208 // BasisSection = true; 209 // } 210 // if (linestring.find("abasis<") != string::npos) { 211 // AuxBasisSection = true; 212 // } 213 // } 214 // // refresh atom::nr and atom::name 215 // newmol->getAtomCount(); 66 bool Psi3Section = false; 67 bool GeometrySection = false; 68 char line[MAXSTRINGSIZE]; 69 typedef boost::tokenizer<boost::char_separator<char> > tokenizer; 70 boost::char_separator<char> sep("()"); 71 boost::char_separator<char> angularsep("<>"); 72 boost::char_separator<char> equalitysep(" ="); 73 boost::char_separator<char> whitesep(" \t"); 74 ConvertTo<double> toDouble; 75 76 molecule *newmol = World::getInstance().createMolecule(); 77 newmol->ActiveFlag = true; 78 // TODO: Remove the insertion into molecule when saving does not depend on them anymore. Also, remove molecule.hpp include 79 World::getInstance().getMolecules()->insert(newmol); 80 while (file->good()) { 81 file->getline(line, MAXSTRINGSIZE-1); 82 std::string linestring(line); 83 LOG(3, "INFO: Current line is: " << line); 84 if ((linestring.find(")") != string::npos) && (linestring.find("(") == string::npos)) { 85 LOG(3, "INFO: Line contains ')' and no '(' (end of section): " << line); 86 // ends a section which do not overlap 87 if (GeometrySection) 88 GeometrySection = false; 89 else 90 Psi3Section = false; 91 } 92 if (GeometrySection) { // we have an atom 93 tokenizer tokens(linestring, sep); 94 // if (tokens.size() != 2) 95 // throw Psi3ParseException; 96 tokenizer::iterator tok_iter = tokens.begin(); 97 ASSERT(tok_iter != tokens.end(), 98 "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!"); 99 std::stringstream whitespacefilter(*++tok_iter); 100 std::string element; 101 whitespacefilter >> ws >> element; 102 LOG(2, "INFO: element of atom is " << element); 103 ASSERT(tok_iter != tokens.end(), 104 "FormatParser< psi3 >::load() - missing token for MoleculeSection in line "+linestring+"!"); 105 std::string vector = *tok_iter; 106 tokenizer vectorcomponents(vector, whitesep); 107 Vector X; 108 // if (vectorcomponents.size() != NDIM) 109 // throw Psi3ParseException; 110 tok_iter = vectorcomponents.begin(); 111 ++tok_iter; 112 for (int i=0; i<NDIM; ++i) { 113 LOG(4, "INFO: Current value is " << *tok_iter << "."); 114 X[i] = toDouble(*tok_iter++); 115 } 116 LOG(2, "INFO: position of atom is " << X); 117 // create atom 118 atom *newAtom = World::getInstance().createAtom(); 119 newAtom->setType(World::getInstance().getPeriode()->FindElement(element)); 120 newAtom->setPosition(X); 121 newmol->AddAtom(newAtom); 122 DoLog(1) && (Log() << Verbose(1) << "Adding atom " << *newAtom << std::endl); 123 } 124 if ((Psi3Section) && (!GeometrySection)) { 125 if (linestring.find("=") != string::npos) { // get param value 126 tokenizer tokens(linestring, equalitysep); 127 tokenizer::iterator tok_iter = tokens.begin(); 128 ASSERT(tok_iter != tokens.end(), 129 "FormatParser< psi3 >::load() - missing token before '=' for Psi3Section in line "+linestring+"!"); 130 std::stringstream whitespacefilter(*tok_iter); 131 std::string key; 132 whitespacefilter >> ws >> key; 133 //LOG(2, "INFO: key to check is: " << key); 134 if (getParams().haveParameter(key)) { 135 //LOG(2, "INFO: Line submitted to parameter is: " << linestring); 136 std::stringstream linestream(linestring); 137 linestream >> getParams(); 138 } else { // unknown keys are simply ignored as long as parser is incomplete 139 LOG(3, "INFO: '"+key+"' is unknown and ignored."); 140 } 141 } 142 } 143 if ((linestring.find("geometry") != string::npos) && (linestring.find("(") != string::npos)) { 144 LOG(3, "INFO: Line contains geometry and '(': " << line); 145 GeometrySection = true; 146 } 147 if ((linestring.find("psi:") != string::npos) && (linestring.find("(") != string::npos)) { 148 LOG(3, "INFO: Line contains psi: and '(': " << line); 149 Psi3Section = true; 150 } 151 } 152 // refresh atom::nr and atom::name 153 newmol->getAtomCount(); 216 154 } 217 155 -
src/Parser/unittests/ParserPsi3UnitTest.cpp
r7f570c r032f31 267 267 268 268 void ParserPsi3UnitTest::readPsi3Test() { 269 // stringstream input(waterPsi3_CLHF); 270 // params->setParameter( 271 // Psi3Parser_Parameters::theoryParam, 272 // params->getTheoryName(Psi3Parser_Parameters::CLHF) 273 // ); 274 // parser->load(&input); 275 // 276 // CPPUNIT_ASSERT_EQUAL(3, World::getInstance().numAtoms()); 269 stringstream input(hydrogenPsi3_RHF); 270 // set some other parameter for jobtype 271 params->setParameter( 272 Psi3Parser_Parameters::jobtypeParam, 273 params->ValidJobtypes[Psi3Parser_Parameters::OPT] 274 ); 275 parser->load(&input); 276 277 // check for jobtype from file 278 CPPUNIT_ASSERT(params->getParameter(Psi3Parser_Parameters::jobtypeParam) == params->ValidJobtypes[Psi3Parser_Parameters::SP]); 279 // check for 2 hydrogens 280 CPPUNIT_ASSERT_EQUAL(2, World::getInstance().numAtoms()); 281 // check that positions are right 282 Vector PositionSum; 283 std::vector<atom *> atoms = World::getInstance().getAllAtoms(); 284 for (std::vector<atom *>::const_iterator iter = atoms.begin(); 285 iter != atoms.end(); 286 ++iter) 287 PositionSum += (*iter)->getPosition(); 288 CPPUNIT_ASSERT_EQUAL( PositionSum, Vector(0,0,0.74) ); 277 289 } 278 290
Note:
See TracChangeset
for help on using the changeset viewer.