Changeset bb6193 for src


Ignore:
Timestamp:
Aug 28, 2010, 12:57:56 AM (15 years ago)
Author:
Frederik Heber <heber@…>
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:
21585f
Parents:
5c6946
git-author:
Frederik Heber <heber@…> (08/27/10 10:37:13)
git-committer:
Frederik Heber <heber@…> (08/28/10 00:57:56)
Message:

Added PdbParser with save capability.

  • load does not yet work.
  • added test part to Simple_configuration/2 (new file test.pdb)
Location:
src/Parser
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/Parser/FormatParserStorage.cpp

    r5c6946 rbb6193  
    2828#include "Parser/MpqcParser.hpp"
    2929#include "Parser/PcpParser.hpp"
     30#include "Parser/PdbParser.hpp"
    3031#include "Parser/TremoloParser.hpp"
    3132#include "Parser/XyzParser.hpp"
     
    5859  ParserNames[mpqc] = "mpqc";
    5960  ParserNames[pcp] = "pcp";
     61  ParserNames[pdb] = "pdb";
    6062  ParserNames[tremolo] = "tremolo";
    6163  ParserNames[xyz] = "xyz";
     
    6668  ParserSuffix[mpqc] = "in";
    6769  ParserSuffix[pcp] = "conf";
     70  ParserSuffix[pdb] = "pdb";
    6871  ParserSuffix[tremolo] = "data";
    6972  ParserSuffix[xyz] = "xyz";
     
    7174  ParserAddFunction[mpqc] = &FormatParserStorage::addMpqc;
    7275  ParserAddFunction[pcp] = &FormatParserStorage::addPcp;
     76  ParserAddFunction[pdb] = &FormatParserStorage::addPdb;
    7377  ParserAddFunction[tremolo] = &FormatParserStorage::addTremolo;
    7478  ParserAddFunction[xyz] = &FormatParserStorage::addXyz;
     
    135139  } else
    136140    DoeLog(1) && (eLog() << Verbose(1) << "Parser pcp is already present." << endl);
     141}
     142
     143
     144/** Adds an PdbParser to the storage.
     145 */
     146void FormatParserStorage::addPdb()
     147{
     148  if (!ParserPresent[pdb]) {
     149    ParserList[pdb] = new PdbParser();
     150    ParserPresent[pdb] = true;
     151  } else
     152    DoeLog(1) && (eLog() << Verbose(1) << "Parser pdb is already present." << endl);
    137153}
    138154
     
    203219  } else if (suffix == ParserSuffix[pcp]) {
    204220    getPcp().load(&input);
     221  } else if (suffix == ParserSuffix[pdb]) {
     222    getPdb().load(&input);
    205223  } else if (suffix == ParserSuffix[tremolo]) {
    206224    getTremolo().load(&input);
     
    234252}
    235253
     254/** Returns reference to the output PdbParser, adds if not present.
     255 * \return reference to the output PdbParser
     256 */
     257PdbParser &FormatParserStorage::getPdb()
     258{
     259  if (!ParserPresent[pdb])
     260    addPdb();
     261  return dynamic_cast<PdbParser &>(*ParserList[pdb]);
     262}
     263
    236264/** Returns reference to the output TremoloParser, adds if not present.
    237265 * \return reference to the output TremoloParser
  • src/Parser/FormatParserStorage.hpp

    r5c6946 rbb6193  
    2222class FormatParser;
    2323class MpqcParser;
     24class PdbParser;
    2425class PcpParser;
    2526class TremoloParser;
     
    2728
    2829// enum has to be outside of class for operator++ to be possible
    29 enum ParserTypes { mpqc, pcp, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc };
     30enum ParserTypes { mpqc, pcp, pdb, tremolo, xyz, ParserTypes_end, ParserTypes_begin = mpqc };
    3031typedef enum ParserTypes ParserTypes;
    3132
     
    3839  void addMpqc();
    3940  void addPcp();
     41  void addPdb();
    4042  void addTremolo();
    4143  void addXyz();
     
    4648  MpqcParser &getMpqc();
    4749  PcpParser &getPcp();
     50  PdbParser &getPdb();
    4851  TremoloParser &getTremolo();
    4952  XyzParser &getXyz();
  • src/Parser/PdbParser.cpp

    r5c6946 rbb6193  
    2626#include "World.hpp"
    2727#include "atom.hpp"
     28#include "bond.hpp"
    2829#include "element.hpp"
    29 #include "bond.hpp"
     30#include "molecule.hpp"
    3031#include "periodentafel.hpp"
    3132#include "Descriptors/AtomIdDescriptor.hpp"
     33
    3234#include <map>
    3335#include <vector>
    3436
     37#include <iostream>
     38#include <iomanip>
    3539
    3640using namespace std;
     
    4044 */
    4145PdbParser::PdbParser() {
    42   knownKeys[" "] = TremoloKey::noKey; // with this we can detect invalid keys
    43   knownKeys["x"] = TremoloKey::x;
    44   knownKeys["u"] = TremoloKey::u;
    45   knownKeys["F"] = TremoloKey::F;
    46   knownKeys["stress"] = TremoloKey::stress;
    47   knownKeys["Id"] = TremoloKey::Id;
    48   knownKeys["neighbors"] = TremoloKey::neighbors;
    49   knownKeys["imprData"] = TremoloKey::imprData;
    50   knownKeys["GroupMeasureTypeNo"] = TremoloKey::GroupMeasureTypeNo;
    51   knownKeys["Type"] = TremoloKey::Type;
    52   knownKeys["extType"] = TremoloKey::extType;
    53   knownKeys["name"] = TremoloKey::name;
    54   knownKeys["resName"] = TremoloKey::resName;
    55   knownKeys["chainID"] = TremoloKey::chainID;
    56   knownKeys["resSeq"] = TremoloKey::resSeq;
    57   knownKeys["occupancy"] = TremoloKey::occupancy;
    58   knownKeys["tempFactor"] = TremoloKey::tempFactor;
    59   knownKeys["segID"] = TremoloKey::segID;
    60   knownKeys["Charge"] = TremoloKey::Charge;
    61   knownKeys["charge"] = TremoloKey::charge;
    62   knownKeys["GrpTypeNo"] = TremoloKey::GrpTypeNo;
    63   knownKeys["torsion"] = TremoloKey::torsion;
    64 
    65   // default behavior: use all possible keys on output
    66   for (std::map<std::string, TremoloKey::atomDataKey>::iterator iter = knownKeys.begin(); iter != knownKeys.end(); ++iter)
    67     usedFields.push_back(iter->first);
     46  knownKeys[" "] = PdbKey::noKey; // with this we can detect invalid keys
     47  knownKeys["x"] = PdbKey::x;
     48  knownKeys["Id"] = PdbKey::Id;
     49  knownKeys["Type"] = PdbKey::Type;
     50  knownKeys["extType"] = PdbKey::extType;
     51  knownKeys["name"] = PdbKey::name;
     52  knownKeys["resName"] = PdbKey::resName;
     53  knownKeys["chainID"] = PdbKey::chainID;
     54  knownKeys["resSeq"] = PdbKey::resSeq;
     55  knownKeys["occupancy"] = PdbKey::occupancy;
     56  knownKeys["tempFactor"] = PdbKey::tempFactor;
     57  knownKeys["segID"] = PdbKey::segID;
     58  knownKeys["charge"] = PdbKey::charge;
    6859}
    6960
     
    7263 */
    7364PdbParser::~PdbParser() {
    74   usedFields.clear();
    7565  additionalAtomData.clear();
    7666  atomIdMap.clear();
     
    8474 */
    8575void PdbParser::load(istream* file) {
    86   string line;
    87   string::size_type location;
    88 
    89   usedFields.clear();
    90   while (file->good()) {
    91     std::getline(*file, line, '\n');
    92     if (usedFields.empty()) {
    93       location = line.find("ATOMDATA", 0);
    94       if (location != string::npos) {
    95        parseAtomDataKeysLine(line, location + 8);
     76//  string line;
     77//  string::size_type location;
     78//
     79//  usedFields.clear();
     80//  while (file->good()) {
     81//    std::getline(*file, line, '\n');
     82//    if (usedFields.empty()) {
     83//      location = line.find("ATOMDATA", 0);
     84//      if (location != string::npos) {
     85//       parseAtomDataKeysLine(line, location + 8);
     86//      }
     87//    }
     88//    if (line.length() > 0 && line.at(0) != '#') {
     89//      readAtomDataLine(line);
     90//    }
     91//  }
     92//
     93//  processNeighborInformation();
     94//  adaptImprData();
     95//  adaptTorsion();
     96}
     97
     98/**
     99 * Saves the World's current state into as a tremolo file.
     100 *
     101 * \param file where to save the state
     102 */
     103void PdbParser::save(ostream* file) {
     104  DoLog(0) && (Log() << Verbose(0) << "Saving changes to pdb." << std::endl);
     105
     106  {
     107    // add initial remark
     108    *file << "REMARK created by molecuilder on ";
     109    time_t now = time((time_t *)NULL);   // Get the system time and put it into 'now' as 'calender time'
     110    // ctime ends in \n\0, we have to cut away the newline
     111    std::string time(ctime(&now));
     112    size_t pos = time.find('\n');
     113    if (pos != 0)
     114      *file << time.substr(0,pos);
     115    else
     116      *file << time;
     117    *file << endl;
     118  }
     119
     120  {
     121    vector<atom *> AtomList = World::getInstance().getAllAtoms();
     122
     123    std::vector<int> elementNo(MAX_ELEMENTS,1);
     124    char name[MAXSTRINGSIZE];
     125
     126    // write ATOMs
     127    int AtomNo = 1; // serial number starts at 1 in pdb
     128    int MolNo = 1;  // residue number starts at 1 in pdb
     129    for (vector<atom *>::iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
     130      const size_t  Z = (*atomIt)->getType()->getAtomicNumber();
     131      sprintf(name, "%2s%02d",(*atomIt)->getType()->getSymbol().c_str(), elementNo[Z]);
     132      elementNo[Z] = (elementNo[Z]+1) % 100;   // confine to two digits
     133      const molecule *mol = (*atomIt)->getMolecule();
     134      if (mol == NULL) {  // for homeless atoms, MolNo = 0 is reserved
     135        MolNo = 0;
     136      } else {
     137        MolNo = mol->getId();
    96138      }
     139      saveLine(file, *atomIt, name, AtomNo, MolNo);
     140      atomIdMap.insert( pair<int, int>((*atomIt)->getId(), AtomNo) );
     141      AtomNo++;
    97142    }
    98     if (line.length() > 0 && line.at(0) != '#') {
    99       readAtomDataLine(line);
     143
     144    // write CONECTs
     145    for (vector<atom *>::iterator atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
     146      writeNeighbors(file, 4, *atomIt);
    100147    }
    101148  }
    102149
    103   processNeighborInformation();
    104   adaptImprData();
    105   adaptTorsion();
    106 }
    107 
    108 /**
    109  * Saves the World's current state into as a tremolo file.
    110  *
    111  * \param file where to save the state
    112  */
    113 void PdbParser::save(ostream* file) {
    114   DoLog(0) && (Log() << Verbose(0) << "Saving changes to tremolo." << std::endl);
    115 
    116   vector<atom*>::iterator atomIt;
    117   vector<string>::iterator it;
    118 
    119   *file << "# ATOMDATA";
    120   for (it=usedFields.begin(); it < usedFields.end(); it++) {
    121     *file << "\t" << *it;
    122   }
     150  // END
     151  *file << "END" << endl;
     152}
     153
     154/**
     155 * Writes one line of tremolo-formatted data to the provided stream.
     156 *
     157 * \param stream where to write the line to
     158 * \param *currentAtom the atom of which information should be written
     159 * \param *name name of atom, i.e. H01
     160 * \param AtomNo serial number of atom
     161 * \param ResidueNo number of residue
     162 */
     163void PdbParser::saveLine(ostream* file, const atom* currentAtom, const char *name, const int AtomNo, const int ResidueNo) {
     164  *file << "ATOM ";
     165  *file << setw(6) << AtomNo; /* atom serial number */
     166  *file << setw(1) << " ";
     167  *file << setfill(' ') << left << setw(4) << name << right;  /* atom name */
     168  *file << setw(1) << " ";
     169  *file << setfill(' ') << setw(3) << ((currentAtom->getMolecule() != NULL) ? currentAtom->getMolecule()->getName().substr(0,3) : "-");  /* residue name */
     170  *file << setw(1) << " ";
     171  *file << setfill(' ') << setw(1) << (char)('a'+(unsigned char)(AtomNo % 26)); /* letter for chain */
     172  *file << setw(4) << ResidueNo; /* residue sequence number */
     173  *file << setw(4) << "    ";
     174  for (int i=0;i<NDIM;i++) {
     175    *file << setw(8) << setprecision(3) << showpoint << currentAtom->at(i); /* positional coordinate in Angstroem */
     176  }
     177  *file << setw(6) << setprecision(2) << showpoint << (double)currentAtom->getType()->getValence(); /* occupancy */
     178  *file << setw(6) << setprecision(2) << showpoint << (double)currentAtom->getType()->getNoValenceOrbitals(); /* temperature factor */
     179  *file << noshowpoint;
     180  *file << setw(6) << "      ";
     181  *file << setw(4) << "0";
     182  *file << setfill(' ') << setw(2) << currentAtom->getType()->getSymbol();
     183  *file << setw(2) << "0";
     184
    123185  *file << endl;
    124   vector<atom *> AtomList = World::getInstance().getAllAtoms();
    125   for (atomIt = AtomList.begin(); atomIt != AtomList.end(); atomIt++) {
    126     saveLine(file, *atomIt);
    127   }
    128 }
    129 
    130 /**
    131  * Sets the keys for which data should be written to the stream when save is
    132  * called.
    133  *
    134  * \param string of field names with the same syntax as for an ATOMDATA line
    135  *        but without the prexix "ATOMDATA"
    136  */
    137 void PdbParser::setFieldsForSave(std::string atomDataLine) {
    138   parseAtomDataKeysLine(atomDataLine, 0);
    139 }
    140 
    141 
    142 /**
    143  * Writes one line of tremolo-formatted data to the provided stream.
    144  *
    145  * \param stream where to write the line to
    146  * \param reference to the atom of which information should be written
    147  */
    148 void PdbParser::saveLine(ostream* file, atom* currentAtom) {
    149   vector<string>::iterator it;
    150   TremoloKey::atomDataKey currentField;
    151 
    152   for (it = usedFields.begin(); it != usedFields.end(); it++) {
    153     currentField = knownKeys[it->substr(0, it->find("="))];
    154     switch (currentField) {
    155       case TremoloKey::x :
    156         // for the moment, assume there are always three dimensions
    157         *file << currentAtom->at(0) << "\t";
    158         *file << currentAtom->at(1) << "\t";
    159         *file << currentAtom->at(2) << "\t";
    160         break;
    161       case TremoloKey::u :
    162         // for the moment, assume there are always three dimensions
    163         *file << currentAtom->AtomicVelocity[0] << "\t";
    164         *file << currentAtom->AtomicVelocity[1] << "\t";
    165         *file << currentAtom->AtomicVelocity[2] << "\t";
    166         break;
    167       case TremoloKey::Type :
    168         *file << currentAtom->getType()->getSymbol() << "\t";
    169         break;
    170       case TremoloKey::Id :
    171         *file << currentAtom->getId() << "\t";
    172         break;
    173       case TremoloKey::neighbors :
    174         writeNeighbors(file, atoi(it->substr(it->find("=") + 1, 1).c_str()), currentAtom);
    175         break;
    176       default :
    177         *file << (additionalAtomData.find(currentAtom->getId()) != additionalAtomData.end()
    178           ? additionalAtomData[currentAtom->getId()].get(currentField)
    179           : defaultAdditionalData.get(currentField));
    180         *file << "\t";
    181         break;
     186}
     187
     188/**
     189 * Writes the neighbor information of one atom to the provided stream.
     190 *
     191 * \param *file  where to write neighbor information to
     192 * \param MaxnumberOfNeighbors of neighbors
     193 * \param *currentAtom to the atom of which to take the neighbor information
     194 */
     195void PdbParser::writeNeighbors(ostream* file, int MaxnumberOfNeighbors, atom* currentAtom) {
     196  if (!currentAtom->ListOfBonds.empty()) {
     197    *file << "CONECT";
     198    int MaxNo = 0;
     199    for(BondList::iterator currentBond = currentAtom->ListOfBonds.begin(); currentBond != currentAtom->ListOfBonds.end(); ++currentBond) {
     200      if (MaxNo < MaxnumberOfNeighbors) {
     201        ASSERT(atomIdMap.find((*currentBond)->GetOtherAtom(currentAtom)->getId()) != atomIdMap.end(), "Id of atom not stored in PdbParser::atomIdMap.");
     202        *file << setw(5) << atomIdMap[(*currentBond)->GetOtherAtom(currentAtom)->getId()];
     203      }
     204      MaxNo++;
    182205    }
    183   }
    184 
    185   *file << endl;
    186 }
    187 
    188 /**
    189  * Writes the neighbor information of one atom to the provided stream.
    190  *
    191  * \param stream where to write neighbor information to
    192  * \param number of neighbors
    193  * \param reference to the atom of which to take the neighbor information
    194  */
    195 void PdbParser::writeNeighbors(ostream* file, int numberOfNeighbors, atom* currentAtom) {
    196   BondList::iterator currentBond = currentAtom->ListOfBonds.begin();
    197   for (int i = 0; i < numberOfNeighbors; i++) {
    198     *file << (currentBond != currentAtom->ListOfBonds.end()
    199         ? (*currentBond)->GetOtherAtom(currentAtom)->getId() : 0) << "\t";
    200   }
    201 }
    202 
    203 /**
    204  * Stores keys from the ATOMDATA line.
    205  *
    206  * \param line to parse the keys from
    207  * \param with which offset the keys begin within the line
    208  */
    209 void PdbParser::parseAtomDataKeysLine(string line, int offset) {
    210   string keyword;
    211   stringstream lineStream;
    212 
    213   lineStream << line.substr(offset);
    214   usedFields.clear();
    215   while (lineStream.good()) {
    216     lineStream >> keyword;
    217     if (knownKeys[keyword.substr(0, keyword.find("="))] == TremoloKey::noKey) {
    218       // TODO: throw exception about unknown key
    219       cout << "Unknown key: " << keyword << " is not part of the tremolo format specification." << endl;
    220       break;
    221     }
    222     usedFields.push_back(keyword);
     206    *file << endl;
    223207  }
    224208}
     
    231215 */
    232216void PdbParser::readAtomDataLine(string line) {
    233   vector<string>::iterator it;
    234   stringstream lineStream;
    235   atom* newAtom = World::getInstance().createAtom();
    236   TremoloAtomInfoContainer *atomInfo = NULL;
    237   additionalAtomData[newAtom->getId()] = *(new TremoloAtomInfoContainer);
    238   atomInfo = &additionalAtomData[newAtom->getId()];
    239   TremoloKey::atomDataKey currentField;
    240   string word;
    241   int oldId;
    242   double tmp;
    243 
    244   lineStream << line;
    245   for (it = usedFields.begin(); it < usedFields.end(); it++) {
    246     currentField = knownKeys[it->substr(0, it->find("="))];
    247     switch (currentField) {
    248       case TremoloKey::x :
    249         // for the moment, assume there are always three dimensions
    250         for (int i=0;i<NDIM;i++) {
    251           lineStream >> tmp;
    252           newAtom->set(i, tmp);
    253         }
    254         break;
    255       case TremoloKey::u :
    256         // for the moment, assume there are always three dimensions
    257         lineStream >> newAtom->AtomicVelocity[0];
    258         lineStream >> newAtom->AtomicVelocity[1];
    259         lineStream >> newAtom->AtomicVelocity[2];
    260         break;
    261       case TremoloKey::Type :
    262         char type[3];
    263         lineStream >> type;
    264         newAtom->setType(World::getInstance().getPeriode()->FindElement(type));
    265         ASSERT(newAtom->getType(), "Type was not set for this atom");
    266         break;
    267       case TremoloKey::Id :
    268         lineStream >> oldId;
    269         atomIdMap[oldId] = newAtom->getId();
    270         break;
    271       case TremoloKey::neighbors :
    272         readNeighbors(&lineStream,
    273             atoi(it->substr(it->find("=") + 1, 1).c_str()), newAtom->getId());
    274         break;
    275       default :
    276         lineStream >> word;
    277         atomInfo->set(currentField, word);
    278         break;
    279     }
    280   }
     217//  vector<string>::iterator it;
     218//  stringstream lineStream;
     219//  atom* newAtom = World::getInstance().createAtom();
     220//  PdbAtomInfoContainer *atomInfo = NULL;
     221//  additionalAtomData[newAtom->getId()] = *(new PdbAtomInfoContainer);
     222//  atomInfo = &additionalAtomData[newAtom->getId()];
     223//  PdbKey::atomDataKey currentField;
     224//  string word;
     225//  int oldId;
     226//  double tmp;
     227//
     228//  lineStream << line;
     229//  for (it = usedFields.begin(); it < usedFields.end(); it++) {
     230//    currentField = knownKeys[it->substr(0, it->find("="))];
     231//    switch (currentField) {
     232//      case PdbKey::x :
     233//        // for the moment, assume there are always three dimensions
     234//        for (int i=0;i<NDIM;i++) {
     235//          lineStream >> tmp;
     236//          newAtom->set(i, tmp);
     237//        }
     238//        break;
     239//      case PdbKey::u :
     240//        // for the moment, assume there are always three dimensions
     241//        lineStream >> newAtom->AtomicVelocity[0];
     242//        lineStream >> newAtom->AtomicVelocity[1];
     243//        lineStream >> newAtom->AtomicVelocity[2];
     244//        break;
     245//      case PdbKey::Type :
     246//        char type[3];
     247//        lineStream >> type;
     248//        newAtom->setType(World::getInstance().getPeriode()->FindElement(type));
     249//        ASSERT(newAtom->getType(), "Type was not set for this atom");
     250//        break;
     251//      case PdbKey::Id :
     252//        lineStream >> oldId;
     253//        atomIdMap[oldId] = newAtom->getId();
     254//        break;
     255//      case PdbKey::neighbors :
     256//        readNeighbors(&lineStream,
     257//            atoi(it->substr(it->find("=") + 1, 1).c_str()), newAtom->getId());
     258//        break;
     259//      default :
     260//        lineStream >> word;
     261//        atomInfo->set(currentField, word);
     262//        break;
     263//    }
     264//  }
    281265}
    282266
     
    289273 */
    290274void PdbParser::readNeighbors(stringstream* line, int numberOfNeighbors, int atomId) {
    291   int neighborId = 0;
    292   for (int i = 0; i < numberOfNeighbors; i++) {
    293     *line >> neighborId;
    294     // 0 is used to fill empty neighbor positions in the tremolo file.
    295     if (neighborId > 0) {
    296       additionalAtomData[atomId].neighbors.push_back(neighborId);
    297     }
    298   }
    299 }
    300 
    301 /**
    302  * Checks whether the provided name is within the list of used fields.
    303  *
    304  * \param field name to check
    305  *
    306  * \return true if the field name is used
    307  */
    308 bool PdbParser::isUsedField(string fieldName) {
    309   bool fieldNameExists = false;
    310   for (vector<string>::iterator usedField = usedFields.begin(); usedField != usedFields.end(); usedField++) {
    311     if (usedField->substr(0, usedField->find("=")) == fieldName)
    312       fieldNameExists = true;
    313   }
    314 
    315   return fieldNameExists;
    316 }
    317 
     275//  int neighborId = 0;
     276//  for (int i = 0; i < numberOfNeighbors; i++) {
     277//    *line >> neighborId;
     278//    // 0 is used to fill empty neighbor positions in the tremolo file.
     279//    if (neighborId > 0) {
     280//      additionalAtomData[atomId].neighbors.push_back(neighborId);
     281//    }
     282//  }
     283}
    318284
    319285/**
     
    323289 */
    324290void PdbParser::processNeighborInformation() {
    325   if (!isUsedField("neighbors")) {
    326     return;
    327   }
    328 
    329   for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
    330     currentInfo != additionalAtomData.end(); currentInfo++
    331   ) {
    332     for(vector<int>::iterator neighbor = currentInfo->second.neighbors.begin();
    333       neighbor != currentInfo->second.neighbors.end(); neighbor++
    334     ) {
    335       World::getInstance().getAtom(AtomById(currentInfo->first))
    336           ->addBond(World::getInstance().getAtom(AtomById(atomIdMap[*neighbor])));
    337     }
    338   }
     291//  if (!isUsedField("neighbors")) {
     292//    return;
     293//  }
     294//
     295//  for(map<int, PdbAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
     296//    currentInfo != additionalAtomData.end(); currentInfo++
     297//  ) {
     298//    for(vector<int>::iterator neighbor = currentInfo->second.neighbors.begin();
     299//      neighbor != currentInfo->second.neighbors.end(); neighbor++
     300//    ) {
     301//      World::getInstance().getAtom(AtomById(currentInfo->first))
     302//          ->addBond(World::getInstance().getAtom(AtomById(atomIdMap[*neighbor])));
     303//    }
     304//  }
    339305}
    340306
     
    349315 */
    350316string PdbParser::adaptIdDependentDataString(string data) {
    351   // there might be no IDs
    352   if (data == "-") {
    353     return "-";
    354   }
    355 
    356   char separator;
    357   int id;
    358   stringstream line, result;
    359   line << data;
    360 
    361   line >> id;
    362   result << atomIdMap[id];
    363   while (line.good()) {
    364     line >> separator >> id;
    365     result << separator << atomIdMap[id];
    366   }
    367 
    368   return result.str();
    369 }
    370 
    371 /**
    372  * Corrects the atom IDs in each imprData entry to the corresponding world IDs
    373  * as they might differ from the originally read IDs.
    374  */
    375 void PdbParser::adaptImprData() {
    376   if (!isUsedField("imprData")) {
    377     return;
    378   }
    379 
    380   for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
    381     currentInfo != additionalAtomData.end(); currentInfo++
    382   ) {
    383     currentInfo->second.imprData = adaptIdDependentDataString(currentInfo->second.imprData);
    384   }
    385 }
    386 
    387 /**
    388  * Corrects the atom IDs in each torsion entry to the corresponding world IDs
    389  * as they might differ from the originally read IDs.
    390  */
    391 void PdbParser::adaptTorsion() {
    392   if (!isUsedField("torsion")) {
    393     return;
    394   }
    395 
    396   for(map<int, TremoloAtomInfoContainer>::iterator currentInfo = additionalAtomData.begin();
    397     currentInfo != additionalAtomData.end(); currentInfo++
    398   ) {
    399     currentInfo->second.torsion = adaptIdDependentDataString(currentInfo->second.torsion);
    400   }
    401 }
    402 
    403 
    404 TremoloAtomInfoContainer::TremoloAtomInfoContainer() :
    405   F("0"),
    406   stress("0"),
    407   imprData("-"),
    408   GroupMeasureTypeNo("0"),
    409   extType("-"),
     317//  // there might be no IDs
     318//  if (data == "-") {
     319//    return "-";
     320//  }
     321//
     322//  char separator;
     323//  int id;
     324//  stringstream line, result;
     325//  line << data;
     326//
     327//  line >> id;
     328//  result << atomIdMap[id];
     329//  while (line.good()) {
     330//    line >> separator >> id;
     331//    result << separator << atomIdMap[id];
     332//  }
     333//
     334//  return result.str();
     335  return "";
     336}
     337
     338
     339PdbAtomInfoContainer::PdbAtomInfoContainer() :
    410340  name("-"),
    411341  resName("-"),
     
    415345  tempFactor("0"),
    416346  segID("0"),
    417   Charge("0"),
    418   charge("0"),
    419   GrpTypeNo("0"),
    420   torsion("-"),
    421   neighbors(vector<int>(0, 5))
     347  charge("0")
    422348{}
    423349
    424 void TremoloAtomInfoContainer::set(TremoloKey::atomDataKey key, string value) {
     350void PdbAtomInfoContainer::set(PdbKey::PdbDataKey key, string value) {
    425351  switch (key) {
    426     case TremoloKey::F :
    427       F = value;
    428       break;
    429     case TremoloKey::stress :
    430       stress = value;
    431      break;
    432     case TremoloKey::imprData :
    433       imprData = value;
    434       break;
    435     case TremoloKey::GroupMeasureTypeNo :
    436       GroupMeasureTypeNo = value;
    437       break;
    438     case TremoloKey::extType :
     352    case PdbKey::extType :
    439353      extType = value;
    440354      break;
    441     case TremoloKey::name :
     355    case PdbKey::name :
    442356      name = value;
    443357      break;
    444     case TremoloKey::resName :
     358    case PdbKey::resName :
    445359      resName = value;
    446360      break;
    447     case TremoloKey::chainID :
     361    case PdbKey::chainID :
    448362      chainID = value;
    449363      break;
    450     case TremoloKey::resSeq :
     364    case PdbKey::resSeq :
    451365      resSeq = value;
    452366      break;
    453     case TremoloKey::occupancy :
     367    case PdbKey::occupancy :
    454368      occupancy = value;
    455369      break;
    456     case TremoloKey::tempFactor :
     370    case PdbKey::tempFactor :
    457371      tempFactor = value;
    458372      break;
    459     case TremoloKey::segID :
     373    case PdbKey::segID :
    460374      segID = value;
    461375      break;
    462     case TremoloKey::Charge :
    463       Charge = value;
    464       break;
    465     case TremoloKey::charge :
     376    case PdbKey::charge :
    466377      charge = value;
    467       break;
    468     case TremoloKey::GrpTypeNo :
    469       GrpTypeNo = value;
    470       break;
    471     case TremoloKey::torsion :
    472       torsion = value;
    473378      break;
    474379    default :
     
    478383}
    479384
    480 string TremoloAtomInfoContainer::get(TremoloKey::atomDataKey key) {
     385string PdbAtomInfoContainer::get(PdbKey::PdbDataKey key) {
    481386  switch (key) {
    482     case TremoloKey::F :
    483       return F;
    484     case TremoloKey::stress :
    485       return stress;
    486     case TremoloKey::imprData :
    487       return imprData;
    488     case TremoloKey::GroupMeasureTypeNo :
    489       return GroupMeasureTypeNo;
    490     case TremoloKey::extType :
     387    case PdbKey::extType :
    491388      return extType;
    492     case TremoloKey::name :
     389    case PdbKey::name :
    493390      return name;
    494     case TremoloKey::resName :
     391    case PdbKey::resName :
    495392      return resName;
    496     case TremoloKey::chainID :
     393    case PdbKey::chainID :
    497394      return chainID;
    498     case TremoloKey::resSeq :
     395    case PdbKey::resSeq :
    499396      return resSeq;
    500     case TremoloKey::occupancy :
     397    case PdbKey::occupancy :
    501398      return occupancy;
    502     case TremoloKey::tempFactor :
     399    case PdbKey::tempFactor :
    503400      return tempFactor;
    504     case TremoloKey::segID :
     401    case PdbKey::segID :
    505402      return segID;
    506     case TremoloKey::Charge :
    507       return Charge;
    508     case TremoloKey::charge :
     403    case PdbKey::charge :
    509404      return charge;
    510     case TremoloKey::GrpTypeNo :
    511       return GrpTypeNo;
    512     case TremoloKey::torsion :
    513       return torsion;
    514405    default :
    515406      cout << "Unknown key: " << key << endl;
  • src/Parser/PdbParser.hpp

    r5c6946 rbb6193  
    1313
    1414/**
    15  * Known keys for the ATOMDATA line.
     15 * Known keys for the Pdb line.
    1616 */
    17 class TremoloKey {
     17class PdbKey {
    1818public:
    19   enum atomDataKey {
     19  enum PdbDataKey {
    2020    noKey,
    2121    x,
    22     u,
    23     F,
    24     stress,
    2522    Id,
    26     neighbors,
    27     imprData,
    28     GroupMeasureTypeNo,
    2923    Type,
    3024    extType,
     
    3630    tempFactor,
    3731    segID,
    38     Charge,
    39     charge,
    40     GrpTypeNo,
    41     torsion
     32    charge
    4233  };
    4334};
     
    4637 * Holds tremolo-specific information which is not store in the atom class.
    4738 */
    48 class TremoloAtomInfoContainer {
     39class PdbAtomInfoContainer {
    4940public:
    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;
     41  PdbAtomInfoContainer();
     42  void set(PdbKey::PdbDataKey key, std::string value);
     43  std::string get(PdbKey::PdbDataKey key);
     44  std::string name;
    5745  std::string extType;
    58   std::string name;
    5946  std::string resName;
    6047  std::string chainID;
     
    6350  std::string tempFactor;
    6451  std::string segID;
    65   std::string Charge;
    6652  std::string charge;
    67   std::string GrpTypeNo;
    68   std::string torsion;
    69   std::vector<int> neighbors;
    7053};
    7154
     
    8063  void load(std::istream* file);
    8164  void save(std::ostream* file);
    82   void setFieldsForSave(std::string atomDataLine);
    8365
    8466
     
    9375  bool isUsedField(std::string fieldName);
    9476  void writeNeighbors(std::ostream* file, int numberOfNeighbors, atom* currentAtom);
    95   void saveLine(std::ostream* file, atom* currentAtom);
     77  void saveLine(ostream* file, const atom* currentAtom, const char *name, const int AtomNo, const int ResdueNo);
     78;
    9679
    9780  /**
    9881   * Map to associate the known keys with numbers.
    9982   */
    100   std::map<std::string, TremoloKey::atomDataKey> knownKeys;
    101 
    102   /**
    103    * Fields used in the tremolo file.
    104    */
    105   std::vector<std::string> usedFields;
     83  std::map<std::string, PdbKey::PdbDataKey> knownKeys;
    10684
    10785  /**
     
    10987   * file.
    11088   */
    111   std::map<int, TremoloAtomInfoContainer> additionalAtomData;
     89  std::map<int, PdbAtomInfoContainer> additionalAtomData;
    11290
    11391  /**
    11492   * Default additional atom data.
    11593   */
    116   TremoloAtomInfoContainer defaultAdditionalData;
     94  PdbAtomInfoContainer defaultAdditionalData;
    11795
    11896  /**
Note: See TracChangeset for help on using the changeset viewer.