本文整理汇总了C++中OBPairData::SetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C++ OBPairData::SetAttribute方法的具体用法?C++ OBPairData::SetAttribute怎么用?C++ OBPairData::SetAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBPairData
的用法示例。
在下文中一共展示了OBPairData::SetAttribute方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AddDataToSubstruct
/**
@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;
}
示例2: 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];
}
示例3: ReadMolecule
//.........这里部分代码省略.........
} else if (strstr(buffer,"MOPAC") != NULL) {
// MOPAC output
formatName = "mopout";
break;
} else if (strstr(buffer,"Program PWSCF") != NULL) {
// PWSCF
formatName = "pwscf";
break;
} else if (strstr(buffer,"Welcome to Q-Chem") != NULL) {
// Q-Chem output
formatName = "qcout";
break;
} else if (strstr(buffer,"Amsterdam Density Functional") != NULL) {
// ADF output
// Determine the kind of ADF output
while (ifs.getline(buffer, BUFF_SIZE)) {
if (strstr(buffer, "| A D F |") != NULL) {
formatName = "adfout";
break;
} else if (strstr(buffer, "| B A N D |") != NULL) {
formatName = "adfband";
break;
} else if (strstr(buffer, "| D F T B |") != NULL) {
formatName = "adfdftb";
break;
} else if (strstr(buffer, "DFTB Engine") != NULL) {
// "| D F T B |" is no longer printed in ADF 2018
// Hopefully, "DFTB Engine" will work fine...
formatName = "adfdftb";
break;
}
}
break;
} else if (strstr(buffer,"Northwest Computational Chemistry") != NULL) {
// NWChem output
formatName = "nwo";
break;
} else if (strstr(buffer,"MPQC: Massively Parallel Quantum Chemistry") != NULL) {
// MPQC output
formatName = "mpqc";
break;
} else if (strstr(buffer,"PROGRAM SYSTEM MOLPRO") != NULL) {
// MOLPRO output
formatName = "mpo";
break;
} else if ((strstr(buffer,"Schrodinger, Inc.") != NULL) &&
(strstr(buffer,"Jaguar") != NULL)) {
// Jaguar
formatName = "jout";
break;
} else if (strstr(buffer, "ABINIT") != NULL) {
// Abinit
formatName = "abinit";
break;
} else if (strstr(buffer, "ACES2") != NULL) {
// ACESII
formatName = "acesout";
break;
} else if (strstr(buffer, "CRYSTAL06") != NULL ||
strstr(buffer, "CRYSTAL09") != NULL) {
// CRYSTAL09
formatName = "c09out";
break;
} else if (strstr(buffer, "* O R C A *") != NULL) {
// ORCA
formatName = "orca";
break;
} else if (strstr(buffer, "WELCOME TO SIESTA") != NULL) {
// SIESTA
formatName = "siesta";
break;
}
}
// if we assigned something above, let's try to find it
if (formatName.length())
pFormat = pConv->FindFormat(formatName);
if (pFormat) {
ifs.seekg (0, ios::beg); // reset the stream to the beginning
ifs.clear();
bool success = pFormat->ReadMolecule(pOb, pConv);
// Tag the molecule with the format (e.g., if a program wants to know the kind of "out" or "log" file)
// We have to do this *after* ReadMolecule returns, or the data might be cleared
if (pOb) {
OBPairData *dp = new OBPairData;
dp->SetAttribute("File Format");
dp->SetValue(formatName);
dp->SetOrigin(fileformatInput);
pOb->SetData(dp);
}
return success;
}
obErrorLog.ThrowError(__FUNCTION__,
"Problems reading an output file: Could not determine the format of this file. Please report it to the openbabel-discuss @ lists.sourceforge.net mailing list.", obError);
return(false); // we couldn't figure out the format
}
示例4: Do
//.........这里部分代码省略.........
//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;
}
示例5: ReadMolecule
//.........这里部分代码省略.........
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;
}
示例6: DoTransformations
//.........这里部分代码省略.........
/* 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);
dp->SetOrigin(userInput);
}
else {
// Pair did not exist; make new one
dp = new OBPairData;
dp->SetAttribute(attr);
dp->SetValue(val);
dp->SetOrigin(userInput);
SetData(dp);
}
}
}
itr = pOptions->find("add"); //adds new properties from descriptors in list
if(itr!=pOptions->end())
OBDescriptor::AddProperties(this, itr->second);
itr = pOptions->find("delete"); //deletes the specified properties
if(itr!=pOptions->end())
OBDescriptor::DeleteProperties(this, itr->second);
itr = pOptions->find("append"); //Appends values of descriptors or properties to title
if(itr!=pOptions->end())
{
string title(GetTitle());
title += OBDescriptor::GetValues(this, itr->second);
if(ispunct(title[0]))
title[0]=' ';//a leading punct char is used only as a separator, not at start
SetTitle(Trim(title).c_str());
}
//Filter using OBDescriptor comparison and (older) SMARTS tests
//Continue only if previous test was true.
bool fmatch = true;
itr = pOptions->find("filter");
if(itr!=pOptions->end())
示例7: ComputeCharges
//! \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);
//.........这里部分代码省略.........
示例8: ReadMolecule
//.........这里部分代码省略.........
atom->SetAtomicNum(atoi((char*)vs[1].c_str()));
}
coordinates.push_back(x);
coordinates.push_back(y);
coordinates.push_back(z);
}
else {
translationVectors[numTranslationVectors++].Set(x, y, z);
}
if (!ifs.getline(buffer,BUFF_SIZE)) {
break;
}
tokenize(vs,buffer);
}
// done with reading atoms
natoms = mol.NumAtoms();
if(natoms==0)
return false;
// malloc / memcpy
double *tmpCoords = new double [(natoms)*3];
memcpy(tmpCoords, &coordinates[0], sizeof(double)*natoms*3);
vconf.push_back(tmpCoords);
coordinates.clear();
confDimensions.push_back(3); // always 3D -- OBConformerData allows mixing 2D and 3D structures
}
else if(strstr(buffer,"Dipole moment") != NULL)
{
ifs.getline(buffer,BUFF_SIZE); // actual components X ### Y #### Z ###
tokenize(vs,buffer);
if (vs.size() >= 6)
{
OBVectorData *dipoleMoment = new OBVectorData;
dipoleMoment->SetAttribute("Dipole Moment");
double x, y, z;
x = atof(vs[1].c_str());
y = atof(vs[3].c_str());
z = atof(vs[5].c_str());
dipoleMoment->SetData(x, y, z);
dipoleMoment->SetOrigin(fileformatInput);
mol.SetData(dipoleMoment);
}
if (!ifs.getline(buffer,BUFF_SIZE)) break;
}
else if(strstr(buffer,"Traceless Quadrupole moment") != NULL)
{
ifs.getline(buffer,BUFF_SIZE); // actual components XX ### YY #### ZZ ###
tokenize(vs,buffer);
ifs.getline(buffer,BUFF_SIZE); // actual components XY ### XZ #### YZ ###
tokenize(vs2,buffer);
if ((vs.size() >= 6) && (vs2.size() >= 6))
{
double Q[3][3];
OpenBabel::OBMatrixData *quadrupoleMoment = new OpenBabel::OBMatrixData;
Q[0][0] = atof(vs[1].c_str());
Q[1][1] = atof(vs[3].c_str());
Q[2][2] = atof(vs[5].c_str());
Q[1][0] = Q[0][1] = atof(vs2[1].c_str());
Q[2][0] = Q[0][2] = atof(vs2[3].c_str());
Q[2][1] = Q[1][2] = atof(vs2[5].c_str());
matrix3x3 quad(Q);
quadrupoleMoment->SetAttribute("Traceless Quadrupole Moment");
quadrupoleMoment->SetData(quad);
quadrupoleMoment->SetOrigin(fileformatInput);
示例9: ReadMolecule
//.........这里部分代码省略.........
if (natoms == 0) { // first time reading the molecule, create each atom
atom = mol.NewAtom();
atom->SetAtomicNum(atoi((char*)vs[1].c_str()));
}
coordinates.push_back(x);
coordinates.push_back(y);
coordinates.push_back(z);
}
else {
translationVectors[numTranslationVectors++].Set(x, y, z);
}
if (!ifs.getline(buffer,BUFF_SIZE)) {
break;
}
tokenize(vs,buffer);
}
// done with reading atoms
natoms = mol.NumAtoms();
// malloc / memcpy
double *tmpCoords = new double [(natoms)*3];
memcpy(tmpCoords, &coordinates[0], sizeof(double)*natoms*3);
vconf.push_back(tmpCoords);
coordinates.clear();
confDimensions.push_back(3); // always 3D -- OBConformerData allows mixing 2D and 3D structures
}
else if(strstr(buffer,"Dipole moment") != NULL)
{
ifs.getline(buffer,BUFF_SIZE); // actual components X ### Y #### Z ###
tokenize(vs,buffer);
if (vs.size() >= 6)
{
OBVectorData *dipoleMoment = new OBVectorData;
dipoleMoment->SetAttribute("Dipole Moment");
double x, y, z;
x = atof(vs[1].c_str());
y = atof(vs[3].c_str());
z = atof(vs[5].c_str());
dipoleMoment->SetData(x, y, z);
dipoleMoment->SetOrigin(fileformatInput);
mol.SetData(dipoleMoment);
}
if (!ifs.getline(buffer,BUFF_SIZE)) break;
}
else if(strstr(buffer,"Total atomic charges") != NULL ||
strstr(buffer,"Mulliken atomic charges") != NULL)
{
hasPartialCharges = true;
chargeModel = "Mulliken";
ifs.getline(buffer,BUFF_SIZE); // column headings
ifs.getline(buffer,BUFF_SIZE);
tokenize(vs,buffer);
while (vs.size() >= 3 &&
strstr(buffer,"Sum of ") == NULL)
{
atom = mol.GetAtom(atoi(vs[0].c_str()));
if (!atom)
break;
atom->SetPartialCharge(atof(vs[2].c_str()));
if (!ifs.getline(buffer,BUFF_SIZE)) break;
tokenize(vs,buffer);
}
}
else if (strstr(buffer, "Charges from ESP fit") != NULL)
{
示例10: ReadMolecule
//.........这里部分代码省略.........
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;
}
示例11: if
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;
//.........这里部分代码省略.........
示例12: ReadMolecule
//.........这里部分代码省略.........
mol.SetTitle(defaultTitle);
}
}
else
return(false);
mol.BeginModify();
mol.ReserveAtoms(natoms);
connections.resize(natoms+1);
/***********************************************************************/
// Get Type Bonds, BondOrder, X, Y, Z
double x,y,z;
vector3 v;
char temp_type[10];
int i,j;
double charge;
OBAtom atom;
ttab.SetFromType("MMD");
for (i = 1; i <= natoms; i++)
{
if (!ifs.getline(buffer,BUFF_SIZE))
break;
int end[6], order[6];
sscanf(buffer,"%9s%d%d%d%d%d%d%d%d%d%d%d%d%lf%lf%lf",
temp_type,&end[0],&order[0],&end[1],&order[1],&end[2],&order[2],
&end[3], &order[3], &end[4], &order[4], &end[5], &order[5],
&x, &y, &z);
pair<int,int> tmp;
for ( j = 0 ; j <=5 ; j++ )
{
if ( end[j] > 0 && end[j] > i)
{
tmp.first = end[j];
tmp.second = order[j];
connections[i].push_back(tmp);
}
}
v.SetX(x);
v.SetY(y);
v.SetZ(z);
atom.SetVector(v);
string str = temp_type,str1;
ttab.SetToType("ATN");
ttab.Translate(str1,str);
atom.SetAtomicNum(atoi(str1.c_str()));
ttab.SetToType("INT");
ttab.Translate(str1,str);
atom.SetType(str1);
// stuff for optional fields
buffer[109]='\0';
sscanf(&buffer[101],"%lf", &charge);
atom.SetPartialCharge(charge);
mol.AddAtom(atom);
}
for (i = 1; i <= natoms; i++)
for (j = 0; j < (signed)connections[i].size(); j++)
mol.AddBond(i, connections[i][j].first, connections[i][j].second);
mol.EndModify();
mol.SetPartialChargesPerceived();
// Annotate origin of partial charges
OBPairData *dp = new OBPairData;
dp->SetAttribute("PartialCharges");
dp->SetValue("MACROMODEL");
dp->SetOrigin(fileformatInput);
mol.SetData(dp);
OBBond *bond;
vector<OBBond*>::iterator bi;
for (bond = mol.BeginBond(bi);bond;bond = mol.NextBond(bi))
if (bond->GetBondOrder() == 5 && !bond->IsInRing())
bond->SetBondOrder(1);
if ( natoms != (signed)mol.NumAtoms() )
return(false);
// clean out remaining blank lines
std::streampos ipos;
do
{
ipos = ifs.tellg();
ifs.getline(buffer,BUFF_SIZE);
}
while(strlen(buffer) == 0 && !ifs.eof() );
ifs.seekg(ipos);
return(true);
}