本文整理汇总了C++中OBPairData类的典型用法代码示例。如果您正苦于以下问题:C++ OBPairData类的具体用法?C++ OBPairData怎么用?C++ OBPairData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了OBPairData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ComputeCharges
bool QEqCharges::ComputeCharges(OBMol &mol)
{
///////////////////////////////////////////////////////////////////////////////
//Some OpenBabel bookkeeping that I copied from the Gasteiger scheme
mol.SetPartialChargesPerceived();
OBPairData *dp = new OBPairData;
dp->SetAttribute("PartialCharges");
dp->SetValue("QEq");
dp->SetOrigin(perceived);
mol.SetData(dp);
///////////////////////////////////////////////////////////////////////////////
//Read in atomic information from OpenBabel molecule and parameterize
//Read in total number of atoms
int i, N = mol.NumAtoms();
Hardness = MatrixXd::Zero(N+1, N+1);
Voltage = VectorXd::Zero(N+1);
Electronegativity = VectorXd::Zero(N);
VectorXd BasisSet = VectorXd::Zero(N);
Vector3d Parameters;
FOR_ATOMS_OF_MOL(atom, mol)
{
Parameters = GetParameters(atom->GetAtomicNum(), atom->GetFormalCharge());
i = atom->GetIdx() - 1;
if (Parameters[0] == 0.)
{
stringstream msg;
msg << "Some QEq Parameters not found!" << endl
<< "Parameters not found for atom no. " << i+1 << endl
<< "Atom will be ignored in the charge computation.";
obErrorLog.ThrowError(__FUNCTION__, msg.str(), obError);
}
Electronegativity[i] = Parameters[0];
Hardness(i,i) = Parameters[1];
BasisSet[i] = Parameters[2];
}
示例2: OBPairObject
/**
@since version 2.3
Adds an OBPairData object to each atom and bond in a substructure.
The substructure's atoms are specified in an input parameter, a
vector of atom indx; the bonds are those in the molecule that join
these atoms. The attribute and value of the OBPairObject (the same
for all the added objects) are specified as parameters.
**/
bool AddDataToSubstruct(OBMol* pmol,
const std::vector<int>& atomIdxs,
const std::string& attribute,
const std::string& value)
{
//Add data to atoms
for(unsigned int j=0; j<atomIdxs.size(); ++j)
{
OBAtom* pAtom = pmol->GetAtom(atomIdxs[j]);
if(!pAtom)
continue;
OBPairData* dp = new OBPairData;
dp->SetAttribute(attribute);
dp->SetValue(value);
pAtom->SetData(dp);
}
OBBond* pBond;
vector<OBBond*>::iterator i;
for(pBond = pmol->BeginBond(i); pBond; pBond = pmol->NextBond(i))
{
//Add data to bond if it joins two atoms in list
if(count(atomIdxs.begin(), atomIdxs.end(), pBond->GetBeginAtomIdx())
&& count(atomIdxs.begin(), atomIdxs.end(), pBond->GetEndAtomIdx()))
{
OBPairData* dp = new OBPairData;
dp->SetAttribute(attribute);
dp->SetValue(value);
pBond->SetData(dp);
}
}
return true;
}
示例3: GetAtomSymClass
unsigned int GetAtomSymClass(OBAtom *atom)
{
OBPairData *pd = dynamic_cast<OBPairData*>(atom->GetParent()->GetData("OpenBabel Symmetry Classes"));
if (pd) {
cout << "same? = " << pd->GetValue() << endl;
istringstream iss(pd->GetValue());
std::vector<unsigned int> symmetry_classes;
copy(istream_iterator<unsigned int>(iss),
istream_iterator<unsigned int>(),
back_inserter<vector<unsigned int> >(symmetry_classes));
// Now find the number of unique elements
vector<unsigned int> copy_sym = symmetry_classes;
sort(copy_sym.begin(), copy_sym.end());
vector<unsigned int>::iterator end_pos = unique(copy_sym.begin(), copy_sym.end()); // Requires sorted elements
int nclasses = end_pos - copy_sym.begin();
cout << "sym_class[" << atom->GetIndex() << "] = " << symmetry_classes.at(atom->GetIndex()) << endl;
return symmetry_classes.at(atom->GetIndex());
}
return 99;
}
示例4: chi
//! \return whether partial charges were successfully assigned to this molecule
bool EQEqCharges::ComputeCharges(OBMol &mol)
{
int i, j, a, c, N = mol.NumAtoms();
double cellVolume;
VectorXf chi(N), J(N), b(N), x(N);
MatrixXf J_ij(N, N), A(N, N);
OBUnitCell *obuc;
matrix3x3 unitcell, fourier;
vector3 dx;
int numNeighbors[3];
OBAtom *atom;
// If parameters have not yet been loaded, do that
if (!_paramFileLoaded)
{
if (ParseParamFile())
{
_paramFileLoaded = true;
} else
{
return false;
}
}
// Calculate atomic properties based around their ionic charge
for (i = 0; i < N; i++)
{
atom = mol.GetAtom(i + 1);
a = atom->GetAtomicNum();
c = _chargeCenter[a];
// Fail if ionization data is missing for any atom in the molecule
if (_ionizations[a][c + 1] == -1 || _ionizations[a][c] == -1 || a > TABLE_OF_ELEMENTS_SIZE)
{
obErrorLog.ThrowError(__FUNCTION__, "Insufficient ionization data for atoms in the given molecule. Update `data/eqeqIonizations.txt` with missing information and re-run this function.", obError);
return false;
}
J(i) = _ionizations[a][c + 1] - _ionizations[a][c];
chi(i) = 0.5 * (_ionizations[a][c + 1] + _ionizations[a][c]) - (a == 1? 0 : c * J(i));
}
// If a unit cell is defined, use the periodic Ewald calculation
if (mol.HasData(OBGenericDataType::UnitCell))
{
// Get unit cell and calculate its Fourier transform + volume
obuc = (OBUnitCell *) mol.GetData(OBGenericDataType::UnitCell);
unitcell = obuc->GetCellMatrix();
fourier = (2 * PI * unitcell.inverse()).transpose();
cellVolume = obuc->GetCellVolume();
// Get the number of radial unit cells to use in x, y, and z
numNeighbors[0] = int(ceil(minCellLength / (2.0 * (obuc->GetA())))) - 1;
numNeighbors[1] = int(ceil(minCellLength / (2.0 * (obuc->GetB())))) - 1;
numNeighbors[2] = int(ceil(minCellLength / (2.0 * (obuc->GetC())))) - 1;
for (i = 0; i < N; i++)
{
atom = mol.GetAtom(i + 1);
for (j = 0; j < N; j++)
{
dx = atom->GetVector() - (mol.GetAtom(j + 1))->GetVector();
J_ij(i, j) = GetPeriodicEwaldJij(J(i), J(j), dx, (i == j), unitcell, fourier, cellVolume, numNeighbors);
}
}
// If no unit cell, use the simplified nonperiodic calculation
} else
{
for (i = 0; i < N; i++)
{
atom = mol.GetAtom(i + 1);
for (j = 0; j < N; j++)
{
J_ij(i, j) = GetNonperiodicJij(J(i), J(j), atom->GetDistance(j + 1), (i == j));
}
return false;
}
}
// Formulate problem as A x = b, where x is the calculated partial charges
// First equation is a simple overall balance: sum(Q) = 0
A.row(0) = VectorXf::Ones(N);
b(0) = 0;
// Remaining equations are based off of the fact that, at equilibrium, the
// energy of the system changes equally for a change in any charge:
// dE/dQ_1 = dE/dQ_2 = ... = dE/dQ_N
A.block(1, 0, N - 1, N) = J_ij.block(0, 0, N - 1, N) - J_ij.block(1, 0, N - 1, N);
b.tail(N - 1) = chi.tail(N - 1) - chi.head(N - 1);
// The solution is a list of charges in the system
x = A.colPivHouseholderQr().solve(b);
// Now we are done calculating, pass all this back to OpenBabel molecule
mol.SetPartialChargesPerceived();
OBPairData *dp = new OBPairData;
dp->SetAttribute("PartialCharges");
dp->SetValue("EQEq");
dp->SetOrigin(perceived);
//.........这里部分代码省略.........
示例5: snprintf
bool TinkerFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
if(pmol==NULL)
return false;
//Define some references so we can use the old parameter names
ostream &ofs = *pConv->GetOutStream();
OBMol &mol = *pmol;
bool mmffTypes = pConv->IsOption("m",OBConversion::OUTOPTIONS) != NULL;
unsigned int i;
char buffer[BUFF_SIZE];
OBBond *bond;
vector<OBBond*>::iterator j;
// Before we try output of MMFF94 atom types, check if it works
OBForceField *ff = OpenBabel::OBForceField::FindForceField("MMFF94");
if (mmffTypes && ff && ff->Setup(mol))
mmffTypes = ff->GetAtomTypes(mol);
else
mmffTypes = false; // either the force field isn't available, or it doesn't work
if (!mmffTypes)
snprintf(buffer, BUFF_SIZE, "%6d %-20s MM2 parameters\n",mol.NumAtoms(),mol.GetTitle());
else
snprintf(buffer, BUFF_SIZE, "%6d %-20s MMFF94 parameters\n",mol.NumAtoms(),mol.GetTitle());
ofs << buffer;
ttab.SetFromType("INT");
OBAtom *atom;
string str,str1;
for(i = 1;i <= mol.NumAtoms(); i++)
{
atom = mol.GetAtom(i);
str = atom->GetType();
ttab.SetToType("MM2");
ttab.Translate(str1,str);
if (mmffTypes) {
// Override the MM2 typing
OBPairData *type = (OpenBabel::OBPairData*)atom->GetData("FFAtomType");
if (type)
str1 = type->GetValue().c_str();
}
snprintf(buffer, BUFF_SIZE, "%6d %2s %12.6f%12.6f%12.6f %5d",
i,
etab.GetSymbol(atom->GetAtomicNum()),
atom->GetX(),
atom->GetY(),
atom->GetZ(),
atoi((char*)str1.c_str()));
ofs << buffer;
for (bond = atom->BeginBond(j); bond; bond = atom->NextBond(j))
{
snprintf(buffer, BUFF_SIZE, "%6d", (bond->GetNbrAtom(atom))->GetIdx());
ofs << buffer;
}
ofs << endl;
}
return(true);
}
示例6: OBUnitCell
//.........这里部分代码省略.........
pmol->DeleteAtom(toDelete.at(i));
// Discover units
matrix3x3 conv (1);
tokenize(vs, buffer);
if (strstr(vs[1].c_str(), "alat")) {
conv *= (alat * BOHR_TO_ANGSTROM);
}
else if (strstr(vs[1].c_str(), "crystal")) {
// Set to the zero matrix and test below.
conv = matrix3x3 (0.0);
}
// Add others if needed
// Load new atoms from molecule
ifs.getline(buffer,BUFF_SIZE); // First entry
tokenize(vs, buffer);
int size = vs.size();
while (size == 4) {
atomicNum = OBElements::GetAtomicNum(vs[0].c_str());
x = atof((char*)vs[1].c_str());
y = atof((char*)vs[2].c_str());
z = atof((char*)vs[3].c_str());
// Add atom
OBAtom *atom = pmol->NewAtom();
atom->SetAtomicNum(atomicNum);
vector3 coords (x,y,z);
if (conv.determinant() == 0.0) { // Fractional coords
atom->SetVector(cell->FractionalToCartesian(coords));
}
else {
atom->SetVector(conv * coords);
}
// Reset vars
ifs.getline(buffer,BUFF_SIZE); // First entry
tokenize(vs, buffer);
size = vs.size();
}
}
// Free energy
if (strstr(buffer, "Final energy =")) {
tokenize(vs, buffer);
pmol->SetEnergy(atof(vs[3].c_str()) * RYDBERG_TO_KCAL_PER_MOL);
}
// H - PV = U energy
if (strstr(buffer, "! total energy =")) {
tokenize(vs, buffer);
pmol->SetEnergy(atof(vs[4].c_str()) * RYDBERG_TO_KCAL_PER_MOL);
}
// Enthalphy
if (strstr(buffer, "Final enthalpy =")) {
tokenize(vs, buffer);
hasEnthalpy = true;
enthalpy = atof(vs.at(3).c_str()) * RYDBERG_TO_KCAL_PER_MOL;
pv = enthalpy - pmol->GetEnergy();
}
}
// set final unit cell
pmol->SetData(cell);
// Set enthalpy
if (hasEnthalpy) {
OBPairData *enthalpyPD = new OBPairData();
OBPairData *enthalpyPD_pv = new OBPairData();
OBPairData *enthalpyPD_eV = new OBPairData();
OBPairData *enthalpyPD_pv_eV = new OBPairData();
enthalpyPD->SetAttribute("Enthalpy (kcal/mol)");
enthalpyPD_pv->SetAttribute("Enthalpy PV term (kcal/mol)");
enthalpyPD_eV->SetAttribute("Enthalpy (eV)");
enthalpyPD_pv_eV->SetAttribute("Enthalpy PV term (eV)");
double en_kcal_per_mole = enthalpy;
double pv_kcal_per_mole = pv;
double en_eV = enthalpy / EV_TO_KCAL_PER_MOL;
double pv_eV = pv / EV_TO_KCAL_PER_MOL;
snprintf(tag, BUFF_SIZE, "%f", en_kcal_per_mole);
enthalpyPD->SetValue(tag);
snprintf(tag, BUFF_SIZE, "%f", pv_kcal_per_mole);
enthalpyPD_pv->SetValue(tag);
snprintf(tag, BUFF_SIZE, "%f", en_eV);
enthalpyPD_eV->SetValue(tag);
snprintf(tag, BUFF_SIZE, "%f", pv_eV);
enthalpyPD_pv_eV->SetValue(tag);
pmol->SetData(enthalpyPD);
pmol->SetData(enthalpyPD_pv);
pmol->SetData(enthalpyPD_eV);
pmol->SetData(enthalpyPD_pv_eV);
}
pmol->EndModify();
return true;
}
示例7: snprintf
bool PDBFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
if(pmol==NULL)
return false;
//Define some references so we can use the old parameter names
ostream &ofs = *pConv->GetOutStream();
OBMol &mol = *pmol;
unsigned int i;
char buffer[BUFF_SIZE];
char type_name[10], padded_name[10];
char the_res[10];
char the_chain = ' ';
const char *element_name;
int res_num;
bool het=true;
int model_num = 0;
if (!pConv->IsLast() || pConv->GetOutputIndex() > 1)
{ // More than one molecule record
model_num = pConv->GetOutputIndex(); // MODEL 1-based index
snprintf(buffer, BUFF_SIZE, "MODEL %8d", model_num);
ofs << buffer << endl;
}
// write back all fields (REMARKS, HELIX, SHEET, SITE, ...)
bool compndWritten = false;
bool authorWritten = false;
std::vector<OBGenericData*> pairData = mol.GetAllData(OBGenericDataType::PairData);
for (std::vector<OBGenericData*>::iterator data = pairData.begin(); data != pairData.end(); ++data) {
OBPairData *pd = static_cast<OBPairData*>(*data);
string attr = pd->GetAttribute();
// filter to make sure we are writing pdb fields only
if (attr != "HEADER" && attr != "OBSLTE" && attr != "TITLE" && attr != "SPLIT" &&
attr != "CAVEAT" && attr != "COMPND" && attr != "SOURCE" && attr != "KEYWDS" &&
attr != "EXPDTA" && attr != "NUMMDL" && attr != "MDLTYP" && attr != "AUTHOR" &&
attr != "REVDAT" && attr != "SPRSDE" && attr != "JRNL" && attr != "REMARK" &&
attr != "DBREF" && attr != "DBREF1" && attr != "DBREF2" && attr != "SEQADV" &&
attr != "SEQRES" && attr != "MODRES" && attr != "HET" && attr != "HETNAM" &&
attr != "HETSYN" && attr != "FORMUL" && attr != "HELIX" && attr != "SHEET" &&
attr != "SSBOND" && attr != "LINK" && attr != "CISPEP" && attr != "SITE" &&
attr != "ORIGX1" && attr != "ORIGX2" && attr != "ORIGX3" && attr != "SCALE1" &&
attr != "SCALE2" && attr != "SCALE3" && attr != "MATRIX1" && attr != "MATRIX2" &&
attr != "MATRIX3" && attr != "MODEL")
continue;
if (attr == "COMPND")
compndWritten = true;
if (attr == "AUTHOR")
authorWritten = true;
// compute spacing needed. HELIX, SITE, HET, ... are trimmed when reading
int nSpacing = 6 - attr.size();
for (int i = 0; i < nSpacing; ++i)
attr += " ";
std::string lines = pd->GetValue();
string::size_type last = 0;
string::size_type pos = lines.find('\n');
while (last != string::npos) {
string line = lines.substr(last, pos - last);
if (pos == string::npos)
last = string::npos;
else
last = pos + 1;
pos = lines.find('\n', last);
ofs << attr << line << endl;
}
}
if (!compndWritten) {
if (strlen(mol.GetTitle()) > 0)
snprintf(buffer, BUFF_SIZE, "COMPND %s ",mol.GetTitle());
else
snprintf(buffer, BUFF_SIZE, "COMPND UNNAMED");
ofs << buffer << endl;
}
if (!authorWritten) {
snprintf(buffer, BUFF_SIZE, "AUTHOR GENERATED BY OPEN BABEL %s",BABEL_VERSION);
ofs << buffer << endl;
}
// Write CRYST1 record, containing unit cell parameters, space group
// and Z value (supposed to be 1)
if (pmol->HasData(OBGenericDataType::UnitCell))
{
OBUnitCell *pUC = (OBUnitCell*)pmol->GetData(OBGenericDataType::UnitCell);
if(pUC->GetSpaceGroup()){
string tmpHM=pUC->GetSpaceGroup()->GetHMName();
// Do we have an extended HM symbol, with origin choice as ":1" or ":2" ? If so, remove it.
size_t n=tmpHM.find(":");
if(n!=string::npos) tmpHM=tmpHM.substr(0,n);
snprintf(buffer, BUFF_SIZE,
"CRYST1%9.3f%9.3f%9.3f%7.2f%7.2f%7.2f %-11s 1",
pUC->GetA(), pUC->GetB(), pUC->GetC(),
//.........这里部分代码省略.........
示例8: return
//.........这里部分代码省略.........
if (!getline(ifs,ln))
return false; //creator
if (!getline(ifs, ln))
return false; //comment
// Originally the comment was added to the reaction via:
// pmol->SetComment(Trim(ln));
if (!getline(ifs, ln))
return false; // num reactants, products, and optionally agents
unsigned int nReactants = 0, nProducts = 0, nAgents = 0;
bool ok = ParseComponent(ln.c_str() + 0, &nReactants);
if (!ok)
return false;
ok = ParseComponent(ln.c_str() + 3, &nProducts);
if (!ok)
return false;
if (ln[6] != '\0') { // optional agents
ok = ParseComponent(ln.c_str() + 6, &nAgents);
if (!ok)
return false;
}
if(nReactants + nProducts + nAgents)
{
//Read the first $MOL. The others are read at the end of the previous MOL
if(!getline(ifs, ln))
return false;
if(Trim(ln).find("$MOL")==string::npos)
return false;
}
OBReactionFacade rxnfacade(pmol);
// Note: If we supported it, we could read each of the rxn components directly
// into the returned OBMol instead of having to do a copy. Unfortunately,
// this isn't possible at the moment (MOL format will need some work first).
// Here is some example code to do it:
//
//unsigned int old_numatoms = 0;
//unsigned int compid = 1;
//for (int i = 0; i<nReactants; i++)
//{
// //Read a MOL file using the same OBConversion object but with a different format
// if (!pMolFormat->ReadMolecule(pmol, pConv))
// obErrorLog.ThrowError(__FUNCTION__, "Failed to read a reactant", obWarning);
// unsigned int numatoms = pmol->NumAtoms();
// for (unsigned int idx = old_numatoms + 1; idx <= numatoms; ++idx) {
// OBAtom* atom = pmol->GetAtom(idx);
// rxnfacade.SetRole(atom, REACTANT);
// rxnfacade.SetComponentId(atom, compid);
// }
// old_numatoms = numatoms;
// compid++;
//}
const char* type[3] = {"a reactant", "a product", "an agent"};
OBReactionRole role;
unsigned int num_components;
for(unsigned int N=0; N<3; N++) {
switch(N) {
case 0:
role = REACTANT;
num_components = nReactants;
break;
case 1:
role = PRODUCT;
num_components = nProducts;
break;
case 2:
role = AGENT;
num_components = nAgents;
break;
}
for (int i=0; i<num_components; i++)
{
//Read a MOL file using the same OBConversion object but with a different format
OBMol mol;
if (!pMolFormat->ReadMolecule(&mol, pConv)) {
std::string error = "Failed to read ";
error += type[N];
obErrorLog.ThrowError(__FUNCTION__, error, obWarning);
continue;
}
if (mol.NumAtoms() == 0) {
OBAtom* dummy = mol.NewAtom(); // Treat the empty OBMol as having a single dummy atom
OBPairData *pd = new OBPairData();
pd->SetAttribute("rxndummy");
pd->SetValue("");
pd->SetOrigin(fileformatInput);
dummy->SetData(pd);
}
rxnfacade.AddComponent(&mol, role);
}
}
pmol->SetIsReaction();
return true;
}
示例9: main
//.........这里部分代码省略.........
do {
nonRingAtoms = false;
size = mol.NumAtoms();
for (unsigned int i = 1; i <= size; ++i)
{
atom = mol.GetAtom(i);
if (!atom->IsInRing()) {
mol.DeleteAtom(atom);
nonRingAtoms = true;
break; // don't know how many atoms there are
}
// Previously, we changed atoms to carbon here.
// Now we perform this alchemy in terms of string-rewriting
// once the canonical SMILES is generated
}
} while (nonRingAtoms);
if (mol.NumAtoms() < 3)
continue;
if (mol.NumBonds() == 0)
continue;
do {
nonRingBonds = false;
size = mol.NumBonds();
for (unsigned int i = 0; i < size; ++i)
{
bond = mol.GetBond(i);
if (!bond->IsInRing()) {
mol.DeleteBond(bond);
nonRingBonds = true;
break; // don't know how many bonds there are
}
}
} while (nonRingBonds);
fragments = mol.Separate();
for (unsigned int i = 0; i < fragments.size(); ++i)
{
if (fragments[i].NumAtoms() < 3) // too small to care
continue;
currentCAN = conv.WriteString(&fragments[i], true);
currentCAN = RewriteSMILES(currentCAN); // change elements to "a/A" for compression
if (index.find(currentCAN) != index.end()) { // already got this
index[currentCAN] += 1; // add to the count for bookkeeping
continue;
}
index[currentCAN] = 1; // don't ever write this ring fragment again
// OK, now retrieve the canonical ordering for the fragment
vector<string> canonical_order;
if (fragments[i].HasData("Canonical Atom Order")) {
OBPairData *data = (OBPairData*)fragments[i].GetData("Canonical Atom Order");
tokenize(canonical_order, data->GetValue().c_str());
}
// Write out an XYZ-style file with the CANSMI as the title
cout << fragments[i].NumAtoms() << '\n';
cout << currentCAN << '\n'; // endl causes a flush
vector<string>::iterator can_iter;
unsigned int order;
OBAtom *atom;
fragments[i].Center();
fragments[i].ToInertialFrame();
for (unsigned int index = 0; index < canonical_order.size();
++index) {
order = atoi(canonical_order[index].c_str());
atom = fragments[i].GetAtom(order);
snprintf(buffer, BUFF_SIZE, "C%8.3f%8.3f%8.3f\n",
atom->x(), atom->y(), atom->z());
cout << buffer;
}
}
fragments.clear();
if (index.size() > fragmentCount) {
fragmentCount = index.size();
cerr << " Fragments: " << fragmentCount << endl;
}
} // while reading molecules (in this file)
ifs.close();
ifs.clear();
} // while reading files
// loop through the map and output frequencies
map<string, int>::const_iterator indexItr;
for (indexItr = index.begin(); indexItr != index.end(); ++indexItr) {
cerr << (*indexItr).second << " INDEX " << (*indexItr).first << "\n";
}
return(0);
}
示例10: parameter
//.........这里部分代码省略.........
//If there is a -s option, reference molecule has only those atoms that are matched
//Call the -s option from here
bool ret = _pOpIsoM->Do(pmol, _stext.c_str(), pmap, pConv);
// Get the atoms that were matched
vector<int> ats = _pOpIsoM->GetMatchAtoms();
if(!ats.empty())
{
// Make a vector of the matching atom coordinates...
for(vector<int>::iterator iter=ats.begin(); iter!=ats.end(); ++iter)
_refvec.push_back((pmol->GetAtom(*iter))->GetVector());
// ...and use a vector reference
_align.SetRef(_refvec);
}
// Stop -s option being called normally, although it will still be called once
// in the DoOps loop already started for the current (first) molecule.
pConv->RemoveOption("s",OBConversion::GENOPTIONS);
if(!ret)
{
// the first molecule did not match the -s option so a reference molecule
// could not be made. Keep trying.
_refMol.Clear();
//obErrorLog.ThrowError(__FUNCTION__, "The first molecule did not match the -s option\n"
// "so the reference structure was not derived from it", obWarning, onceOnly);
return false; //not matched
}
}
}
//All molecules
if(pmol->GetDimension()!= _refMol.GetDimension())
{
stringstream ss;
ss << "The molecule" << pmol->GetTitle()
<< " does not have the same dimensions as the reference molecule "
<< _refMol.GetTitle() << " and is ignored.";
obErrorLog.ThrowError(__FUNCTION__, ss.str().c_str(), obError);
return false;
}
if(_pOpIsoM) //Using -s option
{
//Ignore mol if it does not pass -s option
if(!_pOpIsoM->Do(pmol, "", pmap, pConv)) // "" means will use existing parameters
return false;
// Get the atoms equivalent to those in ref molecule
vector<int> ats = _pOpIsoM->GetMatchAtoms();
// Make a vector of their coordinates and get the centroid
vector<vector3> vec;
vector3 centroid;
for(vector<int>::iterator iter=ats.begin(); iter!=ats.end(); ++iter) {
vector3 v = pmol->GetAtom(*iter)->GetVector();
centroid += v;
vec.push_back(v);
}
centroid /= vec.size();
// Do the alignment
_align.SetTarget(vec);
if(!_align.Align())
return false;
// Get the centroid of the reference atoms
vector3 ref_centroid;
for(vector<vector3>::iterator iter=_refvec.begin(); iter!=_refvec.end(); ++iter)
ref_centroid += *iter;
ref_centroid /= _refvec.size();
//subtract the centroid, rotate the target molecule, then add the centroid
matrix3x3 rotmatrix = _align.GetRotMatrix();
for (unsigned int i = 1; i <= pmol->NumAtoms(); ++i)
{
vector3 tmpvec = pmol->GetAtom(i)->GetVector();
tmpvec -= centroid;
tmpvec *= rotmatrix; //apply the rotation
tmpvec += ref_centroid;
pmol->GetAtom(i)->SetVector(tmpvec);
}
}
else //Not using -s option)
{
_align.SetTargetMol(*pmol);
if(!_align.Align())
return false;
_align.UpdateCoords(pmol);
}
//Save rmsd as a property
OBPairData* dp = new OBPairData;
dp->SetAttribute("rmsd");
double val = _align.GetRMSD();
if(val<1e-12)
val = 0.0;
dp->SetValue(toString(val));
dp->SetOrigin(local);
pmol->SetData(dp);
return true;
}
示例11: snprintf
bool MOL2Format::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
if(pmol==NULL)
return false;
//Define some references so we can use the old parameter names
ostream &ofs = *pConv->GetOutStream();
OBMol &mol = *pmol;
bool ligandsOnly = pConv->IsOption("l", OBConversion::OUTOPTIONS)!=NULL;
//The old code follows....
string str,str1;
char buffer[BUFF_SIZE],label[BUFF_SIZE];
char rnum[BUFF_SIZE],rlabel[BUFF_SIZE];
ofs << "@<TRIPOS>MOLECULE" << endl;
str = mol.GetTitle();
if (str.empty())
ofs << "*****" << endl;
else
ofs << str << endl;
snprintf(buffer, BUFF_SIZE," %d %d 0 0 0", mol.NumAtoms(),mol.NumBonds());
ofs << buffer << endl;
ofs << "SMALL" << endl;
OBPairData *dp = (OBPairData*)mol.GetData("PartialCharges");
if (dp != NULL) {
// Tripos spec says:
// NO_CHARGES, DEL_RE, GASTEIGER, GAST_HUCK, HUCKEL, PULLMAN,
// GAUSS80_CHARGES, AMPAC_CHARGES, MULLIKEN_CHARGES, DICT_ CHARGES,
// MMFF94_CHARGES, USER_CHARGES
if (dp->GetValue() == "Mulliken")
ofs << "MULLIKEN_CHARGES" << endl;
else // should pick from the Tripos types
ofs << "GASTEIGER" << endl;
}
else { // No idea what these charges are... all our code sets "PartialCharges"
ofs << "GASTEIGER" << endl;
}
ofs << "Energy = " << mol.GetEnergy() << endl;
if (mol.HasData(OBGenericDataType::CommentData))
{
OBCommentData *cd = (OBCommentData*)mol.GetData(OBGenericDataType::CommentData);
ofs << cd->GetData();
}
ofs << endl;
ofs << "@<TRIPOS>ATOM" << endl;
OBAtom *atom;
OBResidue *res;
vector<OBAtom*>::iterator i;
vector<int> labelcount;
labelcount.resize( etab.GetNumberOfElements() );
ttab.SetFromType("INT");
ttab.SetToType("SYB");
for (atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
{
//
// Use sequentially numbered atom names if no residues
//
snprintf(label,BUFF_SIZE, "%s%d",
etab.GetSymbol(atom->GetAtomicNum()),
++labelcount[atom->GetAtomicNum()]);
strcpy(rlabel,"<1>");
strcpy(rnum,"1");
str = atom->GetType();
ttab.Translate(str1,str);
//
// Use original atom names if there are residues
//
if (!ligandsOnly && (res = atom->GetResidue()) )
{
// use original atom names defined by residue
snprintf(label,BUFF_SIZE,"%s",(char*)res->GetAtomID(atom).c_str());
// make sure that residue name includes its number
snprintf(rlabel,BUFF_SIZE,"%s%d",res->GetName().c_str(), res->GetNum());
snprintf(rnum,BUFF_SIZE,"%d",res->GetNum());
}
snprintf(buffer,BUFF_SIZE,"%7d%1s%-6s%12.4f%10.4f%10.4f%1s%-5s%4s%1s %-8s%10.4f",
atom->GetIdx(),"",label,
atom->GetX(),atom->GetY(),atom->GetZ(),
"",str1.c_str(),
rnum,"",rlabel,
atom->GetPartialCharge());
ofs << buffer << endl;
}
//.........这里部分代码省略.........
示例12: return
bool MOL2Format::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = pOb->CastAndClear<OBMol>();
if(pmol==NULL)
return false;
//Define some references so we can use the old parameter names
istream &ifs = *pConv->GetInStream();
OBMol &mol = *pmol;
//Old code follows...
bool foundAtomLine = false;
char buffer[BUFF_SIZE];
char *comment = NULL;
string str,str1;
vector<string> vstr;
int len;
mol.BeginModify();
for (;;)
{
if (!ifs.getline(buffer,BUFF_SIZE))
return(false);
if (EQn(buffer,"@<TRIPOS>MOLECULE",17))
break;
}
// OK, just read MOLECULE line
int lcount;
int natoms,nbonds;
bool hasPartialCharges = true;
for (lcount=0;;lcount++)
{
if (!ifs.getline(buffer,BUFF_SIZE))
return(false);
if (EQn(buffer,"@<TRIPOS>ATOM",13))
{
foundAtomLine = true;
break;
}
if (lcount == 0)
{
tokenize(vstr,buffer);
if (!vstr.empty())
mol.SetTitle(buffer);
}
else if (lcount == 1)
sscanf(buffer,"%d%d",&natoms,&nbonds);
else if (lcount == 3) // charge descriptions
{
// Annotate origin of partial charges
OBPairData *dp = new OBPairData;
dp->SetAttribute("PartialCharges");
dp->SetValue(buffer);
dp->SetOrigin(fileformatInput);
mol.SetData(dp);
if (strncasecmp(buffer, "NO_CHARGES", 10) == 0)
hasPartialCharges = false;
}
else if (lcount == 4) //energy (?)
{
tokenize(vstr,buffer);
if (!vstr.empty() && vstr.size() == 3)
if (vstr[0] == "Energy")
mol.SetEnergy(atof(vstr[2].c_str()));
}
else if (lcount == 5) //comment
{
if ( buffer[0] )
{
len = (int) strlen(buffer)+1;
//! @todo allow better multi-line comments
// which don't allow ill-formed data to consume memory
// Thanks to Andrew Dalke for the pointer
if (comment != NULL)
delete [] comment;
comment = new char [len];
memcpy(comment,buffer,len);
}
}
}
if (!foundAtomLine)
{
mol.EndModify();
mol.Clear();
obErrorLog.ThrowError(__FUNCTION__, "Unable to read Mol2 format file. No atoms found.", obWarning);
return(false);
}
mol.ReserveAtoms(natoms);
int i;
vector3 v;
OBAtom atom;
double x,y,z,pcharge;
//.........这里部分代码省略.........
示例13: snprintf
bool TinkerFormat::WriteMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = dynamic_cast<OBMol*>(pOb);
if(pmol==NULL)
return false;
//Define some references so we can use the old parameter names
ostream &ofs = *pConv->GetOutStream();
OBMol &mol = *pmol;
bool mm2Types = false;
bool mmffTypes = pConv->IsOption("m",OBConversion::OUTOPTIONS) != NULL;
bool mm3Types = pConv->IsOption("3",OBConversion::OUTOPTIONS) != NULL;
bool classTypes = pConv->IsOption("c", OBConversion::OUTOPTIONS) != NULL;
unsigned int i;
char buffer[BUFF_SIZE];
OBBond *bond;
vector<OBBond*>::iterator j;
// Before we try output of MMFF94 atom types, check if it works
OBForceField *ff = OpenBabel::OBForceField::FindForceField("MMFF94");
if (mmffTypes && ff && ff->Setup(mol))
mmffTypes = ff->GetAtomTypes(mol);
else
mmffTypes = false; // either the force field isn't available, or it doesn't work
if (!mmffTypes && !mm3Types && !classTypes) {
snprintf(buffer, BUFF_SIZE, "%6d %-20s MM2 parameters\n",mol.NumAtoms(),mol.GetTitle());
mm2Types = true;
}
else if (mm3Types)
snprintf(buffer, BUFF_SIZE, "%6d %-20s MM3 parameters\n",mol.NumAtoms(),mol.GetTitle());
else if (classTypes)
snprintf(buffer, BUFF_SIZE, "%6d %-20s Custom parameters\n",mol.NumAtoms(),mol.GetTitle());
else
snprintf(buffer, BUFF_SIZE, "%6d %-20s MMFF94 parameters\n",mol.NumAtoms(),mol.GetTitle());
ofs << buffer;
ttab.SetFromType("INT");
OBAtom *atom;
string str,str1;
int atomType;
for(i = 1;i <= mol.NumAtoms(); i++)
{
atom = mol.GetAtom(i);
str = atom->GetType();
atomType = 0; // Something is very wrong if this doesn't get set below
if (mm2Types) {
ttab.SetToType("MM2");
ttab.Translate(str1,str);
atomType = atoi((char*)str1.c_str());
}
if (mmffTypes) {
// Override the MM2 typing
OBPairData *type = (OpenBabel::OBPairData*)atom->GetData("FFAtomType");
if (type) {
str1 = type->GetValue().c_str();
atomType = atoi((char*)str1.c_str());
}
}
if (mm3Types) {
// convert to integer for MM3 typing
atomType = SetMM3Type(atom);
}
if (classTypes) {
// Atom classes are set by the user, so use those
OBGenericData *data = atom->GetData("Atom Class");
if (data) {
OBPairInteger* acdata = dynamic_cast<OBPairInteger*>(data); // Could replace with C-style cast if willing to live dangerously
if (acdata) {
int ac = acdata->GetGenericValue();
if (ac >= 0)
atomType = ac;
}
}
}
snprintf(buffer, BUFF_SIZE, "%6d %2s %12.6f%12.6f%12.6f %5d",
i,
OBElements::GetSymbol(atom->GetAtomicNum()),
atom->GetX(),
atom->GetY(),
atom->GetZ(),
atomType);
ofs << buffer;
for (bond = atom->BeginBond(j); bond; bond = atom->NextBond(j))
{
snprintf(buffer, BUFF_SIZE, "%6d", (bond->GetNbrAtom(atom))->GetIdx());
ofs << buffer;
}
ofs << endl;
}
return(true);
}
示例14: return
OBBase* OBMol::DoTransformations(const std::map<std::string, std::string>* pOptions, OBConversion* pConv)
{
// Perform any requested transformations
// on a OBMol
//The input map has option letters or name as the key and
//any associated text as the value.
//For normal(non-filter) transforms:
// returns a pointer to the OBMol (this) if ok or NULL if not.
//For filters returns a pointer to the OBMol (this) if there is a match,
//and NULL when not and in addition the OBMol object is deleted NULL.
//This is now a virtual function. The OBBase version just returns the OBMol pointer.
//This is declared in mol.h
//The filter options, s and v allow a obgrep facility.
//Used together they must both be true to allow a molecule through.
//Parse GeneralOptions
if(pOptions->empty())
return this;
// DoOps calls Do() for each of the plugin options in the map
// It normally returns true, even if there are no options but
// can return false if one of the options decides that the
// molecule should not be output. If it is a filtering op, it
// should delete the molecule itself (unlike the -s, --filter options,
// which delete it in this function).
if(!OBOp::DoOps(this, pOptions, pConv))
return (OBBase *)NULL;
bool ret=true;
map<string,string>::const_iterator itr, itr2;
if(pOptions->find("b")!=pOptions->end())
if(!ConvertDativeBonds())
ret=false;
if(pOptions->find("d")!=pOptions->end())
if(!DeleteHydrogens())
ret=false;
if(pOptions->find("h")!=pOptions->end())
if(!AddHydrogens(false, false))
ret=false;
if(pOptions->find("r")!=pOptions->end()) {
StripSalts();
ret = true;
}
itr = pOptions->find("p");
if(itr!=pOptions->end()) {
double pH = strtod(itr->second.c_str(), 0);
if(!AddHydrogens(false, true, pH))
ret=false;
}
if(pOptions->find("c")!=pOptions->end())
Center();
itr = pOptions->find("title"); //Replaces title
if(itr!=pOptions->end())
SetTitle(itr->second.c_str());
itr = pOptions->find("addtotitle"); //Appends text to title
if(itr!=pOptions->end())
{
string title(GetTitle());
title += itr->second;
SetTitle(title.c_str());
}
/* itr = pOptions->find("addformula"); //Appends tab + formula to title
if(itr!=pOptions->end())
{
string title(GetTitle());
title += '\t' + GetSpacedFormula(1,"");//actually unspaced
SetTitle(title.c_str());
}
*/
//Add an extra property to the molecule.
//Parameter has atrribute and value separated by a space
itr = pOptions->find("property");
if(itr!=pOptions->end())
{
string txt(itr->second);
string::size_type pos = txt.find(' ');
if(pos==string::npos)
{
obErrorLog.ThrowError(__FUNCTION__, "Missing property value", obError);
ret=false;
}
else
{
string attr(txt.substr(0,pos)), val(txt.substr(pos+1));
//Update value if it already exists
OBPairData* dp = dynamic_cast<OBPairData*>(GetData(attr));
if(dp) {
dp->SetValue(val);
//.........这里部分代码省略.........
示例15: charges
//.........这里部分代码省略.........
tokenize(vs, buffer);
while (vs.size() == 5) {
double s = atof(vs[4].c_str());
RotatoryStrengthsVelocity.push_back(s);
ifs.getline(buffer, BUFF_SIZE);
tokenize(vs, buffer);
}
}
else if(strstr(buffer, " state X Y Z R(length)")) {
// Rotatory Strengths
ifs.getline(buffer, BUFF_SIZE); // First entry
tokenize(vs, buffer);
while (vs.size() == 5) {
double s = atof(vs[4].c_str());
RotatoryStrengthsLength.push_back(s);
ifs.getline(buffer, BUFF_SIZE);
tokenize(vs, buffer);
}
}
else if (strstr(buffer, "Forces (Hartrees/Bohr)"))
{
ifs.getline(buffer, BUFF_SIZE); // column headers
ifs.getline(buffer, BUFF_SIZE); // ------
ifs.getline(buffer, BUFF_SIZE); // real data
}
else if (strstr(buffer, "Isotropic = ")) // NMR shifts
{
tokenize(vs, buffer);
if (vs.size() >= 4)
{
atom = mol.GetAtom(atoi(vs[0].c_str()));
OBPairData *nmrShift = new OBPairData();
nmrShift->SetAttribute("NMR Isotropic Shift");
string shift = vs[4].c_str();
nmrShift->SetValue(shift);
atom->SetData(nmrShift);
}
}
else if(strstr(buffer,"SCF Done:") != NULL)
{
tokenize(vs,buffer);
mol.SetEnergy(atof(vs[4].c_str()) * HARTEE_TO_KCALPERMOL);
confEnergies.push_back(mol.GetEnergy());
}
/* Temporarily commented out until the handling of energy in OBMol is sorted out
// MP2 energies also use a different syntax
// PM3 energies use a different syntax
else if(strstr(buffer,"E (Thermal)") != NULL)
{
ifs.getline(buffer,BUFF_SIZE); //Headers
ifs.getline(buffer,BUFF_SIZE); //Total energy; what we want
tokenize(vs,buffer);
mol.SetEnergy(atof(vs[1].c_str()));
confEnergies.push_back(mol.GetEnergy());
}
*/
else if(strstr(buffer,"Standard basis:") != NULL)
{
add_unique_pairdata_to_mol(&mol,"basis",buffer,2);
}
else if(strstr(buffer,"Zero-point correction=") != NULL)