Changeset b8d4a3 for src/Parser


Ignore:
Timestamp:
May 2, 2010, 4:47:18 PM (15 years ago)
Author:
Saskia Metzler <metzler@…>
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:
b9b604
Parents:
4415da
Message:

Tremolo format parser

Location:
src/Parser
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/TremoloParser.cpp

    r4415da rb8d4a3  
    66 */
    77
     8#include "Helpers/Assert.hpp"
    89#include "TremoloParser.hpp"
    910#include "World.hpp"
    1011#include "atom.hpp"
    1112#include "element.hpp"
     13#include "bond.hpp"
    1214#include "periodentafel.hpp"
     15#include "Descriptors/AtomIdDescriptor.hpp"
    1316#include <map>
    1417#include <vector>
    1518
     19
    1620using namespace std;
     21using namespace boost;
    1722
    1823/**
     
    2025 */
    2126TremoloParser::TremoloParser() {
    22   knownKeys[" "] = noKey; // so we can detect invalid keys
    23   knownKeys["x"] = x;
    24   knownKeys["u"] = u;
    25   knownKeys["F"] = F;
    26   knownKeys["stress"] = stress;
    27   knownKeys["Id"] = Id;
    28   knownKeys["neighbors"] = neighbors;
    29   knownKeys["imprData"] = imprData;
    30   knownKeys["GroupMeasureTypeNo"] = GroupMeasureTypeNo;
    31   knownKeys["Type"] = Type;
    32   knownKeys["extType"] = extType;
    33   knownKeys["name"] = name;
    34   knownKeys["resName"] = resName;
    35   knownKeys["chainID"] = chainID;
    36   knownKeys["resSeq"] = resSeq;
    37   knownKeys["occupancy"] = occupancy;
    38   knownKeys["tempFactor"] = tempFactor;
    39   knownKeys["segID"] = segID;
    40   knownKeys["Charge"] = Charge;
    41   knownKeys["charge"] = charge;
    42   knownKeys["GrpTypeNo"] = GrpTypeNo;
     27  knownKeys[" "] = TremoloKey::noKey; // with this we can detect invalid keys
     28  knownKeys["x"] = TremoloKey::x;
     29  knownKeys["u"] = TremoloKey::u;
     30  knownKeys["F"] = TremoloKey::F;
     31  knownKeys["stress"] = TremoloKey::stress;
     32  knownKeys["Id"] = TremoloKey::Id;
     33  knownKeys["neighbors"] = TremoloKey::neighbors;
     34  knownKeys["imprData"] = TremoloKey::imprData;
     35  knownKeys["GroupMeasureTypeNo"] = TremoloKey::GroupMeasureTypeNo;
     36  knownKeys["Type"] = TremoloKey::Type;
     37  knownKeys["extType"] = TremoloKey::extType;
     38  knownKeys["name"] = TremoloKey::name;
     39  knownKeys["resName"] = TremoloKey::resName;
     40  knownKeys["chainID"] = TremoloKey::chainID;
     41  knownKeys["resSeq"] = TremoloKey::resSeq;
     42  knownKeys["occupancy"] = TremoloKey::occupancy;
     43  knownKeys["tempFactor"] = TremoloKey::tempFactor;
     44  knownKeys["segID"] = TremoloKey::segID;
     45  knownKeys["Charge"] = TremoloKey::Charge;
     46  knownKeys["charge"] = TremoloKey::charge;
     47  knownKeys["GrpTypeNo"] = TremoloKey::GrpTypeNo;
     48  knownKeys["torsion"] = TremoloKey::torsion;
    4349}
    4450
     
    4753 */
    4854TremoloParser::~TremoloParser() {
    49 }
    50 
    51 /**
    52  * Stores keys from the ATOMDATA line.
    53  *
    54  * \param line to parse the keys from
    55  * \param with which offset the keys begin within the line
    56  */
    57 void TremoloParser::parseAtomDataKeysLine(string line, int offset) {
    58   string keyword;
    59   stringstream lineStream;
    60 
    61   lineStream << line.substr(offset);
    62   while (lineStream.good()) {
    63     lineStream >> keyword;
    64     if (knownKeys[keyword.substr(0, keyword.find("="))] == noKey) {
    65       // throw exception about unknown key
    66       cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl;
    67       break;
    68     }
    69     usedFields.push_back(keyword);
    70   }
    71 }
    72 
    73 /**
    74  * Reads one data line of a tremolo file and interprets it according to the keys
    75  * obtained from the ATOMDATA line.
    76  *
    77  * \param line to parse as an atom
    78  */
    79 void TremoloParser::readAtomDataLine(string line) {
    80   vector<string>::iterator it;
    81   stringstream lineStream;
    82   atom* newAtom = World::getInstance().createAtom();
    83   TremoloAtomInfoContainer atomInfo = *(new TremoloAtomInfoContainer());
    84   atomDataKey currentField;
    85   string word;
    86 
    87   lineStream << line;
    88   for (it=usedFields.begin(); it < usedFields.end(); it++) {
    89     cout << *it << " -- " << it->substr(0, it->find("=")) << " -- " << knownKeys[it->substr(0, it->find("="))] << endl;
    90     currentField = knownKeys[it->substr(0, it->find("="))];
    91     switch (currentField) {
    92       case x :
    93         // for the moment, assume there are always three dimensions
    94         lineStream >> newAtom->x.x[0];
    95         lineStream >> newAtom->x.x[1];
    96         lineStream >> newAtom->x.x[2];
    97         break;
    98       case u :
    99         // for the moment, assume there are always three dimensions
    100         lineStream >> newAtom->v.x[0];
    101         lineStream >> newAtom->v.x[1];
    102         lineStream >> newAtom->v.x[2];
    103         break;
    104       case F :
    105         lineStream >> word;
    106         atomInfo.F = word;
    107         break;
    108       case stress :
    109         lineStream >> word;
    110         atomInfo.F = word;
    111        break;
    112       case Id :
    113         // this ID is not used
    114         break;
    115       case neighbors :
    116         // TODO neighbor information
    117         lineStream >> word;
    118         break;
    119       case imprData :
    120         lineStream >> word;
    121         atomInfo.imprData = word;
    122         break;
    123       case GroupMeasureTypeNo :
    124         lineStream >> word;
    125         atomInfo.GroupMeasureTypeNo = word;
    126         break;
    127       case Type :
    128         char type[3];
    129         lineStream >> type;
    130         newAtom->setType(World::getInstance().getPeriode()->FindElement(type));
    131         break;
    132       case extType :
    133         lineStream >> word;
    134         atomInfo.extType = word;
    135         break;
    136       case name :
    137         lineStream >> word;
    138         atomInfo.name = word;
    139         break;
    140       case resName :
    141         lineStream >> word;
    142         atomInfo.resName = word;
    143         break;
    144       case chainID :
    145         lineStream >> word;
    146         atomInfo.chainID = word;
    147         break;
    148       case resSeq :
    149         lineStream >> word;
    150         atomInfo.resSeq = word;
    151         break;
    152       case occupancy :
    153         lineStream >> word;
    154         atomInfo.occupancy = word;
    155         break;
    156       case tempFactor :
    157         lineStream >> word;
    158         atomInfo.segID = word;
    159         break;
    160       case segID :
    161         lineStream >> word;
    162         atomInfo.F = word;
    163         break;
    164       case Charge :
    165         lineStream >> word;
    166         atomInfo.Charge = word;
    167         break;
    168       case charge :
    169         lineStream >> word;
    170         atomInfo.charge = word;
    171         break;
    172       case GrpTypeNo :
    173         lineStream >> word;
    174         atomInfo.GrpTypeNo = word;
    175         break;
    176       default :
    177         lineStream >> word;
    178         cout << "Unknown key: " << *it << ", word: " << word << endl;
    179         break;
    180     }
    181   }
    182   moreData[newAtom->getId()] = atomInfo;
    183 }
    184 
     55  usedFields.clear();
     56  additionalAtomData.clear();
     57  atomIdMap.clear();
     58  knownKeys.clear();
     59}
    18560
    18661/**
     
    20681    }
    20782  }
     83
     84  processNeighborInformation();
     85  adaptImprData();
     86  adaptTorsion();
    20887}
    20988
     
    21493 */
    21594void TremoloParser::save(ostream* file) {
    216 /*
    217 write header
    218 for (each atom in world) {
    219   write coordinates and additional data
    220 }
    221 */
    222 }
     95  vector<atom*>::iterator atomIt;
     96  vector<string>::iterator it;
     97
     98  *file << "# ATOMDATA";
     99  for (it=usedFields.begin(); it < usedFields.end(); it++) {
     100    *file << "\t" << *it;
     101  }
     102  *file << endl;
     103  vector<atom *> AtomList = World::getInstance().getAllAtoms();
     104  for (atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
     105    saveLine(file, *atomIt);
     106  }
     107}
     108
     109/**
     110 * Sets the keys for which data should be written to the stream when save is
     111 * called.
     112 *
     113 * \param string of field names with the same syntax as for an ATOMDATA line
     114 *        but without the prexix "ATOMDATA"
     115 */
     116void TremoloParser::setFieldsForSave(std::string atomDataLine) {
     117  parseAtomDataKeysLine(atomDataLine, 0);
     118}
     119
     120
     121/**
     122 * Writes one line of tremolo-formatted data to the provided stream.
     123 *
     124 * \param stream where to write the line to
     125 * \param reference to the atom of which information should be written
     126 */
     127void TremoloParser::saveLine(ostream* file, atom* currentAtom) {
     128  vector<string>::iterator it;
     129  TremoloKey::atomDataKey currentField;
     130
     131  for (it = usedFields.begin(); it != usedFields.end(); it++) {
     132    currentField = knownKeys[it->substr(0, it->find("="))];
     133    switch (currentField) {
     134      case TremoloKey::x :
     135        // for the moment, assume there are always three dimensions
     136        *file << currentAtom->x.x[0] << "\t";
     137        *file << currentAtom->x.x[1] << "\t";
     138        *file << currentAtom->x.x[2] << "\t";
     139        break;
     140      case TremoloKey::u :
     141        // for the moment, assume there are always three dimensions
     142        *file << currentAtom->v.x[0] << "\t";
     143        *file << currentAtom->v.x[1] << "\t";
     144        *file << currentAtom->v.x[2] << "\t";
     145        break;
     146      case TremoloKey::Type :
     147        *file << currentAtom->getType()->getSymbol() << "\t";
     148        break;
     149      case TremoloKey::Id :
     150        *file << currentAtom->getId() << "\t";
     151        break;
     152      case TremoloKey::neighbors :
     153        writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom);
     154        break;
     155      default :
     156        *file << (additionalAtomData.find(currentAtom->getId()) != additionalAtomData.end()
     157          ? additionalAtomData[currentAtom->getId()].get(currentField)
     158          : defaultAdditionalData.get(currentField));
     159        *file << "\t";
     160        break;
     161    }
     162  }
     163
     164  *file << endl;
     165}
     166
     167/**
     168 * Writes the neighbor information of one atom to the provided stream.
     169 *
     170 * \param stream where to write neighbor information to
     171 * \param number of neighbors
     172 * \param reference to the atom of which to take the neighbor information
     173 */
     174void TremoloParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
     175  BondList::iterator currentBond = currentAtom->ListOfBonds.begin();
     176  for (int i = 0; i < numberOfNeighbors; i++) {
     177    *file << (currentBond != currentAtom->ListOfBonds.end()
     178        ? (*currentBond)->GetOtherAtom(currentAtom)->getId() : 0) << "\t";
     179  }
     180}
     181
     182/**
     183 * Stores keys from the ATOMDATA line.
     184 *
     185 * \param line to parse the keys from
     186 * \param with which offset the keys begin within the line
     187 */
     188void TremoloParser::parseAtomDataKeysLine(string line, int offset) {
     189  string keyword;
     190  stringstream lineStream;
     191
     192  lineStream << line.substr(offset);
     193  while (lineStream.good()) {
     194    lineStream >> keyword;
     195    if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) {
     196      // throw exception about unknown key
     197      cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl;
     198      break;
     199    }
     200    usedFields.push_back(keyword);
     201  }
     202}
     203
     204/**
     205 * Reads one data line of a tremolo file and interprets it according to the keys
     206 * obtained from the ATOMDATA line.
     207 *
     208 * \param line to parse as an atom
     209 */
     210void TremoloParser::readAtomDataLine(string line) {
     211  vector<string>::iterator it;
     212  stringstream lineStream;
     213  atom* newAtom = World::getInstance().createAtom();
     214  TremoloAtomInfoContainer *atomInfo = NULL;
     215  additionalAtomData[newAtom->getId()] = *(new TremoloAtomInfoContainer);
     216  atomInfo = &additionalAtomData[newAtom->getId()];
     217  TremoloKey::atomDataKey currentField;
     218  string word;
     219  int oldId;
     220
     221  lineStream << line;
     222  for (it = usedFields.begin(); it < usedFields.end(); it++) {
     223    currentField = knownKeys[it->substr(0, it->find("="))];
     224    switch (currentField) {
     225      case TremoloKey::x :
     226        // for the moment, assume there are always three dimensions
     227        lineStream >> newAtom->x.x[0];
     228        lineStream >> newAtom->x.x[1];
     229        lineStream >> newAtom->x.x[2];
     230        break;
     231      case TremoloKey::u :
     232        // for the moment, assume there are always three dimensions
     233        lineStream >> newAtom->v.x[0];
     234        lineStream >> newAtom->v.x[1];
     235        lineStream >> newAtom->v.x[2];
     236        break;
     237      case TremoloKey::Type :
     238        char type[3];
     239        lineStream >> type;
     240        newAtom->setType(World::getInstance().getPeriode()->FindElement(type));
     241        ASSERT(newAtom->getType(), "Type was not set for this atom");
     242        break;
     243      case TremoloKey::Id :
     244        lineStream >> oldId;
     245        atomIdMap[oldId] = newAtom->getId();
     246        break;
     247      case TremoloKey::neighbors :
     248        readNeighbors(&lineStream,
     249            atoi(it->substr(it->find("=") + 1, 1).c_str()), newAtom->getId());
     250        break;
     251      default :
     252        lineStream >> word;
     253        atomInfo->set(currentField, word);
     254        break;
     255    }
     256  }
     257}
     258
     259/**
     260 * Reads neighbor information for one atom from the input.
     261 *
     262 * \param stream where to read the information from
     263 * \param number of neighbors to read
     264 * \param world id of the atom the information belongs to
     265 */
     266void TremoloParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
     267  int neighborId = 0;
     268  for (int i = 0; i < numberOfNeighbors; i++) {
     269    *line >> neighborId;
     270    // 0 is used to fill empty neighbor positions in the tremolo file.
     271    if (neighborId > 0) {
     272      additionalAtomData[atomId].neighbors.push_back(neighborId);
     273    }
     274  }
     275}
     276
     277/**
     278 * Checks whether the provided name is within the list of used fields.
     279 *
     280 * \param field name to check
     281 *
     282 * \return true if the field name is used
     283 */
     284bool TremoloParser::isUsedField(string fieldName) {
     285  bool fieldNameExists = false;
     286  for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) {
     287    if (usedField->substr(0, usedField->find("=")) == fieldName)
     288      fieldNameExists = true;
     289  }
     290
     291  return fieldNameExists;
     292}
     293
     294
     295/**
     296 * Adds the collected neighbor information to the atoms in the world. The atoms
     297 * are found by their current ID and mapped to the corresponding atoms with the
     298 * Id found in the parsed file.
     299 */
     300void TremoloParser::processNeighborInformation() {
     301  if (!isUsedField("neighbors")) {
     302    return;
     303  }
     304
     305  for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
     306    currentInfo != additionalAtomData.end(); currentInfo++
     307  ) {
     308    for(vector<int>::iterator neighbor = currentInfo->second.neighbors.begin();
     309      neighbor != currentInfo->second.neighbors.end(); neighbor++
     310    ) {
     311      World::getInstance().getAtom(AtomById(currentInfo->first))
     312          ->addBond(World::getInstance().getAtom(AtomById(atomIdMap[*neighbor])));
     313    }
     314  }
     315}
     316
     317/**
     318 * Replaces atom IDs read from the file by the corresponding world IDs. All IDs
     319 * IDs of the input string will be replaced; expected separating characters are
     320 * "-" and ",".
     321 *
     322 * \param string in which atom IDs should be adapted
     323 *
     324 * \return input string with modified atom IDs
     325 */
     326string TremoloParser::adaptIdDependentDataString(string data) {
     327  // there might be no IDs
     328  if (data == "-") {
     329    return "-";
     330  }
     331
     332  char separator;
     333  int id;
     334  stringstream line, result;
     335  line << data;
     336
     337  line >> id;
     338  result << atomIdMap[id];
     339  while (line.good()) {
     340    line >> separator >> id;
     341    result << separator << atomIdMap[id];
     342  }
     343
     344  return result.str();
     345}
     346
     347/**
     348 * Corrects the atom IDs in each imprData entry to the corresponding world IDs
     349 * as they might differ from the originally read IDs.
     350 */
     351void TremoloParser::adaptImprData() {
     352  if (!isUsedField("imprData")) {
     353    return;
     354  }
     355
     356  for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
     357    currentInfo != additionalAtomData.end(); currentInfo++
     358  ) {
     359    currentInfo->second.imprData = adaptIdDependentDataString(currentInfo->second.imprData);
     360  }
     361}
     362
     363/**
     364 * Corrects the atom IDs in each torsion entry to the corresponding world IDs
     365 * as they might differ from the originally read IDs.
     366 */
     367void TremoloParser::adaptTorsion() {
     368  if (!isUsedField("torsion")) {
     369    return;
     370  }
     371
     372  for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
     373    currentInfo != additionalAtomData.end(); currentInfo++
     374  ) {
     375    currentInfo->second.torsion = adaptIdDependentDataString(currentInfo->second.torsion);
     376  }
     377}
     378
    223379
    224380TremoloAtomInfoContainer::TremoloAtomInfoContainer() {
    225   name = "none";
    226   /* Add suitable default values.
    227   std::string F;
    228   std::string stress;
    229   std::string imprData;
    230   std::string GroupMeasureTypeNo;
    231   std::string extType;
    232   std::string name;
    233   std::string resName;
    234   std::string chainID;
    235   std::string resSeq;
    236   std::string occupancy;
    237   std::string tempFactor;
    238   std::string segID;
    239   std::string Charge;
    240   std::string charge;
    241   std::string GrpTypeNo;
    242 */
    243 };
     381  F = "0";
     382  stress = "0";
     383  imprData = "-";
     384  GroupMeasureTypeNo = "0";
     385  extType = "-";
     386  name = "-";
     387  resName = "-";
     388  chainID = "0";
     389  resSeq = "0";
     390  occupancy = "0";
     391  tempFactor = "0";
     392  segID = "0";
     393  Charge = "0";
     394  charge = "0";
     395  GrpTypeNo = "0";
     396  torsion = "-";
     397  neighbors = vector<int>(0, 5);
     398}
     399
     400void TremoloAtomInfoContainer::set(TremoloKey::atomDataKey key, string value) {
     401  switch (key) {
     402    case TremoloKey::F :
     403      F = value;
     404      break;
     405    case TremoloKey::stress :
     406      stress = value;
     407     break;
     408    case TremoloKey::imprData :
     409      imprData = value;
     410      break;
     411    case TremoloKey::GroupMeasureTypeNo :
     412      GroupMeasureTypeNo = value;
     413      break;
     414    case TremoloKey::extType :
     415      extType = value;
     416      break;
     417    case TremoloKey::name :
     418      name = value;
     419      break;
     420    case TremoloKey::resName :
     421      resName = value;
     422      break;
     423    case TremoloKey::chainID :
     424      chainID = value;
     425      break;
     426    case TremoloKey::resSeq :
     427      resSeq = value;
     428      break;
     429    case TremoloKey::occupancy :
     430      occupancy = value;
     431      break;
     432    case TremoloKey::tempFactor :
     433      tempFactor = value;
     434      break;
     435    case TremoloKey::segID :
     436      segID = value;
     437      break;
     438    case TremoloKey::Charge :
     439      Charge = value;
     440      break;
     441    case TremoloKey::charge :
     442      charge = value;
     443      break;
     444    case TremoloKey::GrpTypeNo :
     445      GrpTypeNo = value;
     446      break;
     447    case TremoloKey::torsion :
     448      torsion = value;
     449      break;
     450    default :
     451      cout << "Unknown key: " << key << ", value: " << value << endl;
     452      break;
     453  }
     454}
     455
     456string TremoloAtomInfoContainer::get(TremoloKey::atomDataKey key) {
     457  switch (key) {
     458    case TremoloKey::F :
     459      return F;
     460    case TremoloKey::stress :
     461      return stress;
     462    case TremoloKey::imprData :
     463      return imprData;
     464    case TremoloKey::GroupMeasureTypeNo :
     465      return GroupMeasureTypeNo;
     466    case TremoloKey::extType :
     467      return extType;
     468    case TremoloKey::name :
     469      return name;
     470    case TremoloKey::resName :
     471      return resName;
     472    case TremoloKey::chainID :
     473      return chainID;
     474    case TremoloKey::resSeq :
     475      return resSeq;
     476    case TremoloKey::occupancy :
     477      return occupancy;
     478    case TremoloKey::tempFactor :
     479      return tempFactor;
     480    case TremoloKey::segID :
     481      return segID;
     482    case TremoloKey::Charge :
     483      return Charge;
     484    case TremoloKey::charge :
     485      return charge;
     486    case TremoloKey::GrpTypeNo :
     487      return GrpTypeNo;
     488    case TremoloKey::torsion :
     489      return torsion;
     490    default :
     491      cout << "Unknown key: " << key << endl;
     492      return "";
     493  }
     494}
     495
  • src/Parser/TremoloParser.hpp

    r4415da rb8d4a3  
    1313
    1414/**
    15  * Holds tremolo-specific information which is not store in the atom class.
     15 * Known keys for the ATOMDATA line.
    1616 */
    17 class TremoloAtomInfoContainer {
     17class TremoloKey {
    1818public:
    19   TremoloAtomInfoContainer();
    20   std::string F;
    21   std::string stress;
    22   std::string imprData;
    23   std::string GroupMeasureTypeNo;
    24   std::string extType;
    25   std::string name;
    26   std::string resName;
    27   std::string chainID;
    28   std::string resSeq;
    29   std::string occupancy;
    30   std::string tempFactor;
    31   std::string segID;
    32   std::string Charge;
    33   std::string charge;
    34   std::string GrpTypeNo;
    35 };
    36 
    37 /**
    38  * Loads a tremolo file into the World and saves the World as a tremolo file.
    39  */
    40 class TremoloParser:public FormatParser
    41 {
    42 public:
    43   TremoloParser();
    44   ~TremoloParser();
    45   void load(std::istream* file);
    46   void save(std::ostream* file);
    47 
    48 private:
    49   void readAtomDataLine(string line);
    50   void parseAtomDataKeysLine(string line, int offset);
    51 
    52   /**
    53    * Known keys for the ATOMDATA line.
    54    */
    5519  enum atomDataKey {
    5620    noKey,
     
    7438    Charge,
    7539    charge,
    76     GrpTypeNo
     40    GrpTypeNo,
     41    torsion
    7742  };
     43};
     44
     45/**
     46 * Holds tremolo-specific information which is not store in the atom class.
     47 */
     48class TremoloAtomInfoContainer {
     49public:
     50  TremoloAtomInfoContainer();
     51  void set(TremoloKey::atomDataKey key, std::string value);
     52  std::string get(TremoloKey::atomDataKey key);
     53  std::string F;
     54  std::string stress;
     55  std::string imprData;
     56  std::string GroupMeasureTypeNo;
     57  std::string extType;
     58  std::string name;
     59  std::string resName;
     60  std::string chainID;
     61  std::string resSeq;
     62  std::string occupancy;
     63  std::string tempFactor;
     64  std::string segID;
     65  std::string Charge;
     66  std::string charge;
     67  std::string GrpTypeNo;
     68  std::string torsion;
     69  std::vector<int> neighbors;
     70};
     71
     72/**
     73 * Loads a tremolo file into the World and saves the World as a tremolo file.
     74 */
     75class TremoloParser : public FormatParser
     76{
     77public:
     78  TremoloParser();
     79  ~TremoloParser();
     80  void load(std::istream* file);
     81  void save(std::ostream* file);
     82  void setFieldsForSave(std::string atomDataLine);
     83
     84
     85private:
     86  void readAtomDataLine(string line);
     87  void parseAtomDataKeysLine(string line, int offset);
     88  void readNeighbors(std::stringstream* line, int numberOfNeighbors, int atomId);
     89  void processNeighborInformation();
     90  void adaptImprData();
     91  void adaptTorsion();
     92  std::string adaptIdDependentDataString(std::string data);
     93  bool isUsedField(std::string fieldName);
     94  void writeNeighbors(std::ostream* file, int numberOfNeighbors, atom* currentAtom);
     95  void saveLine(std::ostream* file, atom* currentAtom);
    7896
    7997  /**
    8098   * Map to associate the known keys with numbers.
    8199   */
    82   std::map<std::string, atomDataKey> knownKeys;
     100  std::map<std::string, TremoloKey::atomDataKey> knownKeys;
    83101
    84102  /**
     
    91109   * file.
    92110   */
    93   std::map<int, TremoloAtomInfoContainer> moreData;
     111  std::map<int, TremoloAtomInfoContainer> additionalAtomData;
     112
     113  /**
     114   * Default additional atom data.
     115   */
     116  TremoloAtomInfoContainer defaultAdditionalData;
     117
     118  /**
     119   * Maps original atom IDs received from the parsed file to atom IDs in the
     120   * world.
     121   */
     122  std::map<int, int> atomIdMap;
    94123};
    95124
Note: See TracChangeset for help on using the changeset viewer.