本文整理汇总了C++中OBPairData::GetValue方法的典型用法代码示例。如果您正苦于以下问题:C++ OBPairData::GetValue方法的具体用法?C++ OBPairData::GetValue怎么用?C++ OBPairData::GetValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBPairData
的用法示例。
在下文中一共展示了OBPairData::GetValue方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例2: if
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;
}
//.........这里部分代码省略.........
示例3: WriteMolecule
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);
}
示例4: WriteMolecule
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(),
//.........这里部分代码省略.........
示例5: 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);
}
示例6: WriteMolecule
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);
}
示例7: mmff94_validate
//.........这里部分代码省略.........
if (EQn(buffer, " OPTIMOL> # read next", 22))
break;
}
} // while (getline)
ostringstream os;
vector<int>::iterator i;
vector<double>::iterator di;
unsigned int ni;
bool failed;
cout << "--------------------------------------------------------------------------------" << endl;
cout << " " << endl;
cout << " VALIDATE MOLECULE " << c << ": " << mol.GetTitle() << endl;
cout << " " << endl;
cout << "IDX HYB AROM OB_TYPE LOG_TYPE RESULT " << endl;
cout << "---------------------------------------------- " << endl;
//
// validate atom types
//
ni = 1;
failed = false;
for (i = types.begin(); i != types.end();i++) {
if (ni > mol.NumAtoms())
continue;
OBPairData *type = (OBPairData*) mol.GetAtom(ni)->GetData("FFAtomType");
if (!type)
continue;
os.str("");
os << "In molecule " << mol.GetTitle() << ": Wrong atom type for atom ";
os << ni << " # found " << type->GetValue() << ", expected " << *i;
BOOST_CHECK_MESSAGE( atoi(type->GetValue().c_str()) == (*i), os.str().c_str());
if (atoi(type->GetValue().c_str()) == (*i))
snprintf(_logbuf, BUFF_SIZE, "%2d %3d %4d %3d %3d PASSED",
mol.GetAtom(ni)->GetIdx(), mol.GetAtom(ni)->GetHyb(),
mol.GetAtom(ni)->IsAromatic(), atoi(mol.GetAtom(ni)->GetType()), *i);
else {
snprintf(_logbuf, BUFF_SIZE, "%2d %3d %4d %3d %3d XXX FAILED XXX",
mol.GetAtom(ni)->GetIdx(), mol.GetAtom(ni)->GetHyb(),
mol.GetAtom(ni)->IsAromatic(), atoi(type->GetValue().c_str()), *i);
failed = true;
}
cout << _logbuf << endl;
ni++;
}
/*
cout << endl;
cout << "IDX OB_FCARGE LOG_FCHARGE RESULT" << endl;
cout << "----------------------------------------" << endl;
//
// validate formal charges
//
ni = 1;
for (di = fcharges.begin(); di != fcharges.end(); di++) {
if (ni > mol.NumAtoms())
continue;
if (fabs((*di) - mol.GetAtom(ni)->GetPartialCharge()) <= 0.001)