void PDBSystem::_ParseMolecules() { for (Mol_it it = begin_mols(); it != end_mols(); it++) delete *it; _mols.clear(); MolPtr pmol = (MolPtr)NULL; int _currentmol = 0; for (Atom_it it = begin(); it != end(); it++) { // then, if the atom's molid is different than the one we were just on, then readjust the current molecule to something else if ((*it)->MolID() != _currentmol) { MolPtr newmol; newmol = molecule::MoleculeFactory ((*it)->Residue()); _currentmol = (*it)->MolID(); newmol->MolID (_currentmol); newmol->Name ((*it)->Residue()); if (pmol != (MolPtr)NULL) { _mols.push_back (pmol); } pmol = newmol; } pmol->AddAtom(*it); } } // Parse Molecules
distance_pair BondGraph::ClosestAtom (const MolPtr& mol, const Atom::Element_t elmt) const { distance_vec distances; for (Atom_it it = mol->begin(); it != mol->end(); it++) { distances.push_back ((ClosestAtoms (*it, 1, elmt, false))[0]); } pair_utility::pair_sort_first(distances.begin(), distances.end()); return distances[0]; }
/* the mol pointers in the topology file list the beginning and end atoms of each molecule. This function will group all atoms in a molecule, form a molecule object, and add it to the _mols vector */ void AmberSystem::_ParseMolecules () { MolPtr newmol; // Here we run through each mol pointer, create a new molecule, and add in the appropriate atoms for (int mol = 0; mol < _topfile.NumMols(); mol++) { // At each new pointer we create a molecule and start adding in atoms // if the molecule is of a specific type for which a class has been created, then let's use that! std::string name = _topfile.MolNames()[mol]; newmol = molecule::MoleculeFactory(name); newmol->Name(name); //_mols[mol]->Name (name); // set the molecule's residue name newmol->MolID(mol); // Then add all the atoms between the indices of the molpointers in the topology file int molsize = _topfile.MolSizes()[mol]; int molpointer = _topfile.MolPointers()[mol]; for (int atomCount = 0; atomCount < molsize; atomCount++) { // sets the index of the current atom that's being added to the molecule int curAtom = molpointer + atomCount - 1; // Now we're going to bless this new atom with loads of information about itself and its molecule newmol->AddAtom( _atoms[curAtom] ); // add the atom into the molecule } // lastly, tack it into our running list _mols.push_back(newmol); /* // a topology file doesn't give us the type, so that will be determined when creating the new molecules if (name == "no3") { _mols.push_back (new Nitrate()); } else if (name == "hno3") { _mols.push_back (new NitricAcid()); } // we might also have water molecules! else if (name == "h2o") { _mols.push_back (new Water()); } else if (name == "so2" || name == "sog" || name == "soq") { _mols.push_back (new SulfurDioxide()); } else if (name == "dec" || name == "pds") { _mols.push_back (new Decane()); } // otherwise add on a generic molecule else { printf ("AmberSystem::_ParseMolecules() -- Couldn't parse the molecule with name '%s'. Don't know what to do with it\n", name.c_str()); exit(1); } */ } return; }
distance_vec BondGraph::ClosestAtoms (const MolPtr mol, const int num, const Atom::Element_t elmt) const { distance_vec distances; for (Atom_it atom = mol->begin(); atom != mol->end(); atom++) { distance_vec closest = ClosestAtoms (*atom, 10, elmt, false); std::copy (closest.begin(), closest.end(), std::back_inserter(distances)); } pair_utility::pair_sort_first (distances.begin(), distances.end()); distance_vec::const_iterator it = std::unique(distances.begin(), distances.end(), pair_utility::pair_equal_second_pred<distance_pair>()); distances.resize(it - distances.begin()); pair_utility::pair_sort_first (distances.begin(), distances.end()); distances.resize(num); return distances; } // closest Atoms - molecular version
// if given a 2nd molecule, this will merge the current and the new molecules into one larger molecule. MolPtr Molecule::Merge (MolPtr mol) { printf ("merging two molecules:\n"); this->Print(); printf ("mol 2---\n"); mol->Print(); // the new molecule's name is yet unknown _name = "undefined"; _moltype = Molecule::NO_MOLECULE; for (Atom_it it = mol->begin(); it != mol->end(); it++) { this->AddAtom (*it); } return (this); }