double Molecule::getPotential() { //RigidBody* rb; Bond* bond; Bend* bend; Torsion* torsion; //std::vector<RigidBody*> rbIter; std::vector<Bond*> bondIter;; std::vector<Bend*> bendIter; std::vector<Torsion*> torsionIter; double potential = 0; //for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) { // rb->updateAtoms(); //} for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) { potential += bond->getPotential(); } for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) { potential += bend->getPotential(); } for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion = nextTorsion(torsionIter)) { potential += torsion->getPotential(); } return potential; }
bool BondFunctions::isTradable(const Bond& bond, Date settlement) { if (settlement == Date()) settlement = bond.settlementDate(); return bond.notional(settlement)!=0.0; }
// handles stereochem markers set by the Mol file parser and // converts them to the RD standard: void DetectAtomStereoChemistry(RWMol &mol, const Conformer *conf) { PRECONDITION(conf, "no conformer"); // make sure we've calculated the implicit valence on each atom: for (RWMol::AtomIterator atomIt = mol.beginAtoms(); atomIt != mol.endAtoms(); ++atomIt) { (*atomIt)->calcImplicitValence(false); } for (RWMol::BondIterator bondIt = mol.beginBonds(); bondIt != mol.endBonds(); ++bondIt) { Bond *bond = *bondIt; if (bond->getBondDir() != Bond::UNKNOWN) { Bond::BondDir dir = bond->getBondDir(); // the bond is marked as chiral: if (dir == Bond::BEGINWEDGE || dir == Bond::BEGINDASH) { Atom *atom = bond->getBeginAtom(); if (atom->getImplicitValence() == -1) { atom->calcExplicitValence(); atom->calcImplicitValence(); } Atom::ChiralType code = FindAtomStereochemistry(mol, bond, conf); atom->setChiralTag(code); // within the RD representation, if a three-coordinate atom // is chiral and has an implicit H, that H needs to be made explicit: if (atom->getDegree() == 3 && !atom->getNumExplicitHs() && atom->getNumImplicitHs() == 1) { atom->setNumExplicitHs(1); // recalculated number of implicit Hs: atom->updatePropertyCache(); } } } } }
void SetBondOrderCommand::redo() { Bond *bond = editor()->bond(m_atomId1, m_atomId2); assert(bond != 0); bond->setOrder(m_finalOrder); }
TEST(CjsonTest, saveFile) { CjsonFormat cjson; Molecule savedMolecule, molecule; bool success = cjson.readFile(std::string(AVOGADRO_DATA) + "/data/ethane.cjson", savedMolecule); EXPECT_TRUE(success); EXPECT_EQ(cjson.error(), ""); success = cjson.writeFile("ethanetmp.cjson", savedMolecule); EXPECT_TRUE(success); EXPECT_EQ(cjson.error(), ""); // Now read the file back in and check a few key values are still present. success = cjson.readFile("ethanetmp.cjson", molecule); EXPECT_TRUE(success); EXPECT_EQ(cjson.error(), ""); EXPECT_EQ(molecule.data("name").toString(), "Ethane"); EXPECT_EQ(molecule.atomCount(), static_cast<size_t>(8)); EXPECT_EQ(molecule.bondCount(), static_cast<size_t>(7)); Atom atom = molecule.atom(7); EXPECT_EQ(atom.atomicNumber(), static_cast<unsigned char>(1)); EXPECT_EQ(atom.position3d().x(), -1.184988); EXPECT_EQ(atom.position3d().y(), 0.004424); EXPECT_EQ(atom.position3d().z(), -0.987522); Bond bond = molecule.bond(0); EXPECT_EQ(bond.atom1().index(), static_cast<size_t>(0)); EXPECT_EQ(bond.atom2().index(), static_cast<size_t>(1)); EXPECT_EQ(bond.order(), static_cast<unsigned char>(1)); }
TEST(RWMoleculeTest, BondType) { Molecule m; RWMolecule mol(m); typedef RWMolecule::AtomType Atom; typedef RWMolecule::BondType Bond; Atom a0 = mol.addAtom(1); Atom a1 = mol.addAtom(2); Atom a2 = mol.addAtom(3); Bond b0 = mol.addBond(a0, a1); Bond b1 = mol.addBond(1, 2); Bond invalid = mol.addBond(0, 9); EXPECT_TRUE(b0.isValid()); EXPECT_FALSE(invalid.isValid()); EXPECT_FALSE(Bond().isValid()); EXPECT_FALSE(Bond(&mol, 3).isValid()); EXPECT_EQ(&mol, b0.molecule()); EXPECT_EQ(0, b0.index()); EXPECT_EQ(a0, b0.atom1()); EXPECT_EQ(a2, b1.atom2()); b1.setOrder(2); EXPECT_EQ(2, b1.order()); EXPECT_EQ(2, mol.bondOrder(1)); Bond other(&mol, 0); EXPECT_EQ(b0, other); EXPECT_NE(b1, other); }
void FileImportExtension::processLine(QTextStream *in, Molecule *mol) { // First truncate the line, remove trailing white space and check QString line = in->readLine(); QString key = line; key = key.trimmed(); if (key == "%FLAG BONDS_WITHOUT_HYDROGEN") { qDebug() << "Reading in bonds..."; line = in->readLine(); // Throw away this line line = ""; QStringList list; while (line[0] != '%') { line = in->readLine(); list += line.split(' ', QString::SkipEmptyParts); if (list.size() == 30) { for (int i = 0; i <= 27; i += 3) { Bond *bond = mol->addBond(); bond->setAtoms(list.at(i).toInt()/3, list.at(i+1).toInt()/3); //bond->setOrder(list.at(i+2).toInt()); } list.clear(); } } } }
bool KCFFile::readEDGE_(KCFFile::IndexAtomMap& index_to_atom) { if (!getLine().hasPrefix(EDGE_TAG)) { throw Exception::ParseError(__FILE__, __LINE__, String("'") + getLine() + "' (line " + String(getLineNumber()) + " of " + getName() + "'", String("Expected EDGE tag: ")); } Size number_of_edges = getLine().getField(1).toInt(); bool ok = true; for (Position i = 0; ok && (i < number_of_edges); i++) { // Get the next line readLine(); // Make sure the line starts with a blank ok &= getLine().hasPrefix(CONTINUED_LINE); // ??? Comments still mising Position first = getLine().getField(1).toInt(); Position second = getLine().getField(2).toInt(); Position order = getLine().getField(3).toInt(); // Make sure the indices refered to do exist ok &= index_to_atom.has(first) && index_to_atom.has(second); if (ok) { Bond* bond = index_to_atom[first]->createBond(*index_to_atom[second]); bond->setOrder(order); } } return (ok && readLine()); }
// Perform desired function bool BondVariable::performFunction(int i, ReturnValue& rv, TreeNode* node) { Messenger::enter("BondVariable::performFunction"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nFunctions)) { printf("Internal Error: FunctionAccessor id %i is out of range for Bond type.\n", i); Messenger::exit("BondVariable::performFunction"); return false; } // Get current data from ReturnValue bool result = true; Bond* ptr = (Bond*) rv.asPointer(VTypes::BondData, result); if (result) switch (i) { case (BondVariable::Partner): rv.set(VTypes::AtomData, ptr->partner( (Atom*) node->argp(0, VTypes::AtomData))); break; default: printf("Internal Error: Access to function '%s' has not been defined in BondVariable.\n", qPrintable(functionData[i].name)); result = false; break; } Messenger::exit("BondVariable::performFunction"); return result; }
void setNewProductBond(const Bond &origB, RWMOL_SPTR product, unsigned bondBeginIdx, unsigned bondEndIdx) { unsigned bondIdx = product->addBond(bondBeginIdx, bondEndIdx, origB.getBondType()) - 1; Bond *newB = product->getBondWithIdx(bondIdx); newB->setBondDir(origB.getBondDir()); }
///////////////////////////////////////////////////////////////////////////// // Function: Constructor // Purpose: Creates a bond object from an existing Bond struct // Input: A Bond object (passed by ref) // A vector of MIAtom structs containing the atoms in the bond // A vector of corresponding MIAtom objects to use for the new ptrs // Output: None // Note: Correspondence between MIAtom is inferred from their bondOrder // in the vector containers ///////////////////////////////////////////////////////////////////////////// Bond::Bond(const Bond &bond, const MIAtomList &old_atoms, const MIAtomList &new_atoms) { std::string error_message; int i1 = GetIndex(static_cast<MIAtom*> (bond.getAtom1()), old_atoms); int i2 = GetIndex(static_cast<MIAtom*> (bond.getAtom2()), old_atoms); if (i1 < 0 || i2 < 0) { error_message = "Corrupted bond."; throw error_message; } bondOrder = bond.bondOrder; atom1 = new_atoms[i1]; atom2 = new_atoms[i2]; type = bond.type; stereo = bond.stereo; ideal_length = bond.ideal_length; tolerance = bond.tolerance; dict_include = bond.dict_include; isaromatic = bond.isaromatic; iscyclic = bond.iscyclic; ring_system = bond.ring_system; smallest_ring_size = bond.smallest_ring_size; smallest_aromatic_ring = bond.smallest_aromatic_ring; }
Spread BondFunctions::zSpread(const Bond& bond, Real cleanPrice, const shared_ptr<YieldTermStructure>& d, const DayCounter& dayCounter, Compounding compounding, Frequency frequency, Date settlement, Real accuracy, Size maxIterations, Rate guess) { if (settlement == Date()) settlement = bond.settlementDate(); QL_REQUIRE(BondFunctions::isTradable(bond, settlement), "non tradable at " << settlement << " (maturity being " << bond.maturityDate() << ")"); Real dirtyPrice = cleanPrice + bond.accruedAmount(settlement); dirtyPrice /= 100.0 / bond.notional(settlement); return CashFlows::zSpread(bond.cashflows(), d, dirtyPrice, dayCounter, compounding, frequency, false, settlement, settlement, accuracy, maxIterations, guess); }
void Molecule::calcForces() { RigidBody* rb; Bond* bond; Bend* bend; Torsion* torsion; std::vector<RigidBody*> rbIter; std::vector<Bond*> bondIter;; std::vector<Bend*> bendIter; std::vector<Torsion*> torsionIter; for (rb = beginRigidBody(rbIter); rb != NULL; rb = nextRigidBody(rbIter)) { rb->updateAtoms(); } for (bond = beginBond(bondIter); bond != NULL; bond = nextBond(bondIter)) { bond->calcForce(); } for (bend = beginBend(bendIter); bend != NULL; bend = nextBend(bendIter)) { bend->calcForce(); } for (torsion = beginTorsion(torsionIter); torsion != NULL; torsion = nextTorsion(torsionIter)) { torsion->calcForce(); } }
DistanceFinder::DistanceFinder(SimInfo* info) : info_(info) { nObjects_.push_back(info_->getNGlobalAtoms()+info_->getNGlobalRigidBodies()); nObjects_.push_back(info_->getNGlobalBonds()); nObjects_.push_back(info_->getNGlobalBends()); nObjects_.push_back(info_->getNGlobalTorsions()); nObjects_.push_back(info_->getNGlobalInversions()); stuntdoubles_.resize(nObjects_[STUNTDOUBLE]); bonds_.resize(nObjects_[BOND]); bends_.resize(nObjects_[BEND]); torsions_.resize(nObjects_[TORSION]); inversions_.resize(nObjects_[INVERSION]); SimInfo::MoleculeIterator mi; Molecule::AtomIterator ai; Molecule::RigidBodyIterator rbIter; Molecule::BondIterator bondIter; Molecule::BendIterator bendIter; Molecule::TorsionIterator torsionIter; Molecule::InversionIterator inversionIter; Molecule* mol; Atom* atom; RigidBody* rb; Bond* bond; Bend* bend; Torsion* torsion; Inversion* inversion; for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { stuntdoubles_[atom->getGlobalIndex()] = atom; } for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { stuntdoubles_[rb->getGlobalIndex()] = rb; } for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { bonds_[bond->getGlobalIndex()] = bond; } for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { bends_[bend->getGlobalIndex()] = bend; } for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { torsions_[torsion->getGlobalIndex()] = torsion; } for (inversion = mol->beginInversion(inversionIter); inversion != NULL; inversion = mol->nextInversion(inversionIter)) { inversions_[inversion->getGlobalIndex()] = inversion; } } }
Leg::const_iterator BondFunctions::nextCashFlow(const Bond& bond, Date settlement) { if (settlement == Date()) settlement = bond.settlementDate(); return CashFlows::nextCashFlow(bond.cashflows(), false, settlement); }
// addBonds void AmberParm::addBond(Bond& new_bond) { int i = new_bond.getAtomI(); int j = new_bond.getAtomJ(); int natom = (int)atoms_.size(); if (i < 0 || i >= natom || j < 0 || j >= natom) throw AmberParmError("Bond atom index out of range"); bonds_.push_back(new_bond); }
Real BondFunctions::nextCashFlowAmount(const Bond& bond, Date settlement) { if (settlement == Date()) settlement = bond.settlementDate(); return CashFlows::nextCashFlowAmount(bond.cashflows(), false, settlement); }
Date BondFunctions::previousCashFlowDate(const Bond& bond, Date settlement) { if (settlement == Date()) settlement = bond.settlementDate(); return CashFlows::previousCashFlowDate(bond.cashflows(), false, settlement); }
// Retrieve desired value bool BondVariable::retrieveAccessor(int i, ReturnValue& rv, bool hasArrayIndex, int arrayIndex) { Messenger::enter("BondVariable::retrieveAccessor"); // Cast 'i' into Accessors enum value if ((i < 0) || (i >= nAccessors)) { printf("Internal Error: Accessor id %i is out of range for Bond type.\n", i); Messenger::exit("BondVariable::retrieveAccessor"); return false; } Accessors acc = (Accessors) i; // Check for correct lack/presence of array index given if ((accessorData[i].arraySize == 0) && hasArrayIndex) { Messenger::print("Error: Unnecessary array index provided for member '%s'.", qPrintable(accessorData[i].name)); Messenger::exit("BondVariable::retrieveAccessor"); return false; } else if ((accessorData[i].arraySize > 0) && (hasArrayIndex)) { if ((arrayIndex < 1) || (arrayIndex > accessorData[i].arraySize)) { Messenger::print("Error: Array index out of bounds for member '%s' (%i, range is 1-%i).", qPrintable(accessorData[i].name), arrayIndex, accessorData[i].arraySize); Messenger::exit("BondVariable::retrieveAccessor"); return false; } } // Get current data from ReturnValue bool result = true; Bond* ptr = (Bond*) rv.asPointer(VTypes::BondData, result); if ((!result) || (ptr == NULL)) { Messenger::print("Invalid (NULL) %s reference encountered.", VTypes::dataType(VTypes::BondData)); result = false; } if (result) switch (acc) { case (BondVariable::I): rv.set(VTypes::AtomData, ptr->atomI()); break; case (BondVariable::J): rv.set(VTypes::AtomData, ptr->atomJ()); break; case (BondVariable::Order): rv.set(ptr->order()); break; case (BondVariable::Type): rv.set(Bond::bondType(ptr->type())); break; default: printf("Internal Error: Access to member '%s' has not been defined in BondVariable.\n", qPrintable(accessorData[i].name)); result = false; break; } Messenger::exit("BondVariable::retrieveAccessor"); return result; }
void writeInteratomics(Atom *atoms, int numatoms, const double globalCutoff, const TypeVec &types, double *spaceSize, const SquareSelector<double> &coordCutoffs) { // iterate from numatoms to 1 BondMap bonds(types); CoordinationHistogramData coords(types.size()); Bond *file; size_t *count = new size_t[types.size()]; for (int i = numatoms - 1; i > 0; --i) { memset(count, '\0', sizeof(size_t) * types.size()); // iterate from j-1 to 0 for (int j = numatoms - 1; j >= 0; --j) { if (i == j) { continue; } double distance = getDistance(atoms[i], atoms[j], spaceSize); if (distance <= globalCutoff) { file = bonds.getFile(atoms[i].type, atoms[j].type); file->write(distance); } if (!coordCutoffs.empty() && distance <= coordCutoffs.select(atoms[i].type, atoms[j].type)) { count[atoms[j].type] += 1; } } if (!coordCutoffs.empty()) { for (size_t j = 0; j < types.size(); ++j) { coords.addValue(atoms[i].type, j, count[j]); } } } if (!coordCutoffs.empty()) { writeCoordination(coords, types); } delete[] count; }
void Molecule::removeBond(unsigned long id) { if (id < m_bonds.size()) { Q_D(Molecule); if (m_bonds[id] == 0) return; d->invalidRings = true; m_invalidPartialCharges = true; m_invalidAromaticity = true; Bond *bond = m_bonds[id]; m_bonds[id] = 0; // Delete the bond from the list and reorder the remaining bonds int index = bond->index(); m_bondList.removeAt(index); for (int i = index; i < m_bondList.size(); ++i) { m_bondList[i]->setIndex(i); } // Also delete the bond from the attached atoms if (m_atoms.size() > bond->beginAtomId()) { if (m_atoms[bond->beginAtomId()]) m_atoms[bond->beginAtomId()]->removeBond(id); } if (m_atoms.size() > bond->endAtomId()) { if (m_atoms[bond->endAtomId()]) m_atoms[bond->endAtomId()]->removeBond(id); } disconnect(bond, SIGNAL(updated()), this, SLOT(updateBond())); emit bondRemoved(bond); bond->deleteLater(); } }
FOR_BONDS_OF_MOL(obBond, obMol) { Bond *bond = new Bond; bond->setOrder(obBond->GetBondOrder()); bond->setFromAtom(atomMap.value(obBond->GetBeginAtomIdx())); bond->setToAtom(atomMap.value(obBond->GetEndAtomIdx())); m_molecule->addBond(bond); }
Date BondFunctions::referencePeriodEnd(const Bond& bond, Date settlement) { if (settlement == Date()) settlement = bond.settlementDate(); QL_REQUIRE(BondFunctions::isTradable(bond, settlement), "non tradable at " << settlement << " (maturity being " << bond.maturityDate() << ")"); return CashFlows::referencePeriodEnd(bond.cashflows(), false, settlement); }
BigInteger BondFunctions::accruedDays(const Bond& bond, Date settlement) { if (settlement == Date()) settlement = bond.settlementDate(); QL_REQUIRE(BondFunctions::isTradable(bond, settlement), "non tradable at " << settlement << " (maturity being " << bond.maturityDate() << ")"); return CashFlows::accruedDays(bond.cashflows(), false, settlement); }
void addMissingProductBonds(const Bond &origB, RWMOL_SPTR product, ReactantProductAtomMapping *mapping) { unsigned int begIdx = origB.getBeginAtomIdx(); unsigned int endIdx = origB.getEndAtomIdx(); std::vector<unsigned> prodBeginIdxs = mapping->reactProdAtomMap[begIdx]; std::vector<unsigned> prodEndIdxs = mapping->reactProdAtomMap[endIdx]; CHECK_INVARIANT(prodBeginIdxs.size() == prodEndIdxs.size(), "Different number of start-end points for product bonds."); for (unsigned i = 0; i < prodBeginIdxs.size(); i++) { setNewProductBond(origB, product, prodBeginIdxs.at(i), prodEndIdxs.at(i)); } }
Bond* RecordHelper::findCTDinBondMap(std::string CUSIP){ BondRateMap::iterator bondMapIt; for (bondMapIt=_bondRateMap.begin(); bondMapIt!=_bondRateMap.end(); ++bondMapIt){ map<long, Bond>* innerBondMap = &(bondMapIt->second); map<long, Bond>::iterator innerBondMapIt; for (innerBondMapIt=innerBondMap->begin(); innerBondMapIt!=innerBondMap->end(); ++innerBondMapIt){ Bond* tempBond = &(innerBondMapIt->second); if (tempBond->getCUSIP() == CUSIP) return tempBond; } } return NULL; }
void StandardPDBResidueBondOrders(RWMol *mol) { RWMol::BondIterator bondIt; for (bondIt=mol->beginBonds(); bondIt!=mol->endBonds(); ++bondIt) { Bond *bond = *bondIt; if (bond->getBondType() == Bond::SINGLE) { Atom *beg = bond->getBeginAtom(); Atom *end = bond->getEndAtom(); if (StandardPDBDoubleBond(mol,beg,end)) bond->setBondType(Bond::DOUBLE); } } }
Real BondFunctions::accruedAmount(const Bond& bond, Date settlement) { if (settlement == Date()) settlement = bond.settlementDate(); QL_REQUIRE(BondFunctions::isTradable(bond, settlement), "non tradable at " << settlement << " (maturity being " << bond.maturityDate() << ")"); return CashFlows::accruedAmount(bond.cashflows(), false, settlement) * 100.0 / bond.notional(settlement); }
Real BondFunctions::yieldValueBasisPoint(const Bond& bond, const InterestRate& yield, Date settlement) { if (settlement == Date()) settlement = bond.settlementDate(); QL_REQUIRE(BondFunctions::isTradable(bond, settlement), "non tradable at " << settlement << " (maturity being " << bond.maturityDate() << ")"); return CashFlows::yieldValueBasisPoint(bond.cashflows(), yield, false, settlement); }
void IndexFinder::init() { SimInfo::MoleculeIterator mi; Molecule::AtomIterator ai; Molecule::RigidBodyIterator rbIter; Molecule::BondIterator bondIter; Molecule::BendIterator bendIter; Molecule::TorsionIterator torsionIter; Molecule::InversionIterator inversionIter; Molecule* mol; Atom* atom; RigidBody* rb; Bond* bond; Bend* bend; Torsion* torsion; Inversion* inversion; for (mol = info_->beginMolecule(mi); mol != NULL; mol = info_->nextMolecule(mi)) { SelectionSet ss(nObjects_); ss.bitsets_[MOLECULE].setBitOn(mol->getGlobalIndex()); for(atom = mol->beginAtom(ai); atom != NULL; atom = mol->nextAtom(ai)) { ss.bitsets_[STUNTDOUBLE].setBitOn(atom->getGlobalIndex()); } for (rb = mol->beginRigidBody(rbIter); rb != NULL; rb = mol->nextRigidBody(rbIter)) { ss.bitsets_[STUNTDOUBLE].setBitOn(rb->getGlobalIndex()); } for (bond = mol->beginBond(bondIter); bond != NULL; bond = mol->nextBond(bondIter)) { ss.bitsets_[BOND].setBitOn(bond->getGlobalIndex()); } for (bend = mol->beginBend(bendIter); bend != NULL; bend = mol->nextBend(bendIter)) { ss.bitsets_[BEND].setBitOn(bend->getGlobalIndex()); } for (torsion = mol->beginTorsion(torsionIter); torsion != NULL; torsion = mol->nextTorsion(torsionIter)) { ss.bitsets_[TORSION].setBitOn(torsion->getGlobalIndex()); } for (inversion = mol->beginInversion(inversionIter); inversion != NULL; inversion = mol->nextInversion(inversionIter)) { ss.bitsets_[INVERSION].setBitOn(inversion->getGlobalIndex()); } selectionSets_[mol->getGlobalIndex()] = ss; } }