本文整理汇总了C++中OBAtom::SetData方法的典型用法代码示例。如果您正苦于以下问题:C++ OBAtom::SetData方法的具体用法?C++ OBAtom::SetData怎么用?C++ OBAtom::SetData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBAtom
的用法示例。
在下文中一共展示了OBAtom::SetData方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例3: ReadMolecule
// Reading Gaussian output has been tested for G98 and G03 to some degree
// If you have problems (or examples of older output), please contact
// the [email protected] mailing list and/or post a bug
bool GaussianOutputFormat::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;
const char* title = pConv->GetTitle();
char buffer[BUFF_SIZE];
string str,str1;
double x,y,z;
OBAtom *atom;
vector<string> vs;
int charge = 0;
unsigned int spin = 1;
bool hasPartialCharges = false;
string chargeModel; // descriptor for charges (e.g. "Mulliken")
// coordinates of all steps
// Set conformers to all coordinates we adopted
std::vector<double*> vconf; // index of all frames/conformers
std::vector<double> coordinates; // coordinates in each frame
int natoms = 0; // number of atoms -- ensure we don't go to a new job with a different molecule
// OBConformerData stores information about multiple steps
// we can change attribute later if needed (e.g., IRC)
OBConformerData *confData = new OBConformerData();
confData->SetOrigin(fileformatInput);
std::vector<unsigned short> confDimensions = confData->GetDimension(); // to be fair, set these all to 3D
std::vector<double> confEnergies = confData->GetEnergies();
std::vector< std::vector< vector3 > > confForces = confData->GetForces();
//Vibrational data
std::vector< std::vector< vector3 > > Lx;
std::vector<double> Frequencies, Intensities;
//Rotational data
std::vector<double> RotConsts(3);
int RotSymNum=1;
OBRotationData::RType RotorType;
// Translation vectors (if present)
vector3 translationVectors[3];
int numTranslationVectors = 0;
//Electronic Excitation data
std::vector<double> Forces, Wavelengths, EDipole,
RotatoryStrengthsVelocity, RotatoryStrengthsLength;
// Orbital data
std::vector<double> orbitals;
std::vector<std::string> symmetries;
int aHOMO, bHOMO, betaStart;
//Put some metadata into OBCommentData
string comment("Gaussian ");
ifs.getline(buffer,BUFF_SIZE);
if(*buffer)
{
comment += strchr(buffer,'=')+2;
comment += "";
for(unsigned i=0; i<115, ifs; ++i)
{
ifs.getline(buffer,BUFF_SIZE);
if(buffer[1]=='#')
{
//the line describing the method
comment += buffer;
OBCommentData *cd = new OBCommentData;
cd->SetData(comment);
cd->SetOrigin(fileformatInput);
mol.SetData(cd);
break;
}
}
}
int i=0;
bool no_symmetry=false;
char coords_type[25];
//Prescan file to find second instance of "orientation:"
//This will be the kind of coords used in the chk/fchk file
//Unless the "nosym" keyword has been requested
while (ifs.getline(buffer,BUFF_SIZE))
{
if (strstr(buffer,"Symmetry turned off by external request.") != NULL)
{
// The "nosym" keyword has been requested
no_symmetry = true;
}
if (strstr(buffer,"orientation:") !=NULL)
{
i++;
tokenize (vs, buffer);
//.........这里部分代码省略.........
示例4: ReadMolecule
//.........这里部分代码省略.........
}
// Reset end-of-file pointers etc.
ifs.clear();
ifs.seekg(0); //rewind
mol.BeginModify();
while (ifs.getline(buffer,BUFF_SIZE))
{
if(strstr(buffer, "Entering Gaussian") != NULL)
{
//Put some metadata into OBCommentData
string comment("Gaussian ");
if(NULL != strchr(buffer,'='))
{
comment += strchr(buffer,'=')+2;
comment += "";
for(unsigned i=0; i<115 && ifs; ++i)
{
ifs.getline(buffer,BUFF_SIZE);
if(strstr(buffer,"Revision") != NULL)
{
if (buffer[strlen(buffer)-1] == ',')
{
buffer[strlen(buffer)-1] = '\0';
}
add_unique_pairdata_to_mol(&mol,"program",buffer,0);
}
else if(buffer[1]=='#')
{
//the line describing the method
comment += buffer;
OBCommentData *cd = new OBCommentData;
cd->SetData(comment);
cd->SetOrigin(fileformatInput);
mol.SetData(cd);
tokenize(vs,buffer);
if (vs.size() > 1)
{
char *str = strdup(vs[1].c_str());
char *ptr = strchr(str,'/');
if (NULL != ptr)
{
*ptr = ' ';
add_unique_pairdata_to_mol(&mol,"basis",ptr,0);
*ptr = '\0';
add_unique_pairdata_to_mol(&mol,"method",str,0);
}
}
break;
}
}
}
}
else if (strstr(buffer,"Multiplicity") != NULL)
{
tokenize(vs, buffer, " \t\n");
if (vs.size() == 6)
{
total_charge = atoi(vs[2].c_str());
spin_multiplicity = atoi(vs[5].c_str());
}
示例5: main
int main(int argc,char **argv)
{
char *program_name= argv[0];
char *FileIn = NULL;
if (argc != 2)
{
cout << "Usage: " << program_name << " <filename>" << endl;
exit(-1);
}
else
{
FileIn = argv[1];
// const char* p = strrchr(FileIn,'.');
}
// Find Input filetype
OBConversion conv;
OBFormat *format = conv.FormatFromExt(FileIn);
if (!format || !conv.SetInAndOutFormats(format, format))
{
cerr << program_name << ": cannot read input format!" << endl;
exit (-1);
}
ifstream ifs;
// Read the file
ifs.open(FileIn);
if (!ifs)
{
cerr << program_name << ": cannot read input file!" << endl;
exit (-1);
}
OBMol mol;
OBAtom *atom;
for (int c=1;;++c) // big for loop (replace with do while?)
{
mol.Clear();
conv.Read(&mol, &ifs);
if (mol.Empty())
break;
cout << "Molecule "<< c << ": " << mol.GetTitle() << endl;
//mol.FindChiralCenters(); // labels all chiral atoms
vector<OBAtom*>::iterator i; // iterate over all atoms
for (atom = mol.BeginAtom(i);atom;atom = mol.NextAtom(i))
{
if(!atom->IsChiral())continue; // aborts if atom isn't chiral
cout << "Atom " << atom->GetIdx() << " Is Chiral ";
cout << atom->GetType()<<endl;
OBChiralData* cd = (OBChiralData*)atom->GetData(OBGenericDataType::ChiralData);
if (cd){
vector<unsigned int> x=cd->GetAtom4Refs(input);
size_t n=0;
cout <<"Atom4refs:";
for (n=0;n<x.size();++n)
cout <<" "<<x[n];
cout <<endl;
}
else{cd=new OBChiralData;atom->SetData(cd);}
vector<unsigned int> _output;
unsigned int n;
for(n=1;n<5;++n) _output.push_back(n);
cd->SetAtom4Refs(_output,output);
/* // MOLV3000 uses 1234 unless an H then 123H
if (atom->GetHvyValence()==3)
{
OBAtom *nbr;
int Hid=1000;// max Atom ID +1 should be used here
vector<unsigned int> nbr_atms;
vector<OBBond*>::iterator i;
for (nbr = atom->BeginNbrAtom(i);nbr;nbr = atom->NextNbrAtom(i))
{
if (nbr->IsHydrogen()){Hid=nbr->GetIdx();continue;}
nbr_atms.push_back(nbr->GetIdx());
}
sort(nbr_atms.begin(),nbr_atms.end());
nbr_atms.push_back(Hid);
OBChiralData* cd=(OBChiralData*)atom->GetData(OBGenericDataType::ChiralData);
cd->SetAtom4Refs(nbr_atms,output);
}
else if (atom->GetHvyValence()==4)
{
OBChiralData* cd=(OBChiralData*)atom->GetData(OBGenericDataType::ChiralData);
vector<unsigned int> nbr_atms;
int n;
for(n=1;n<5;++n)nbr_atms.push_back(n);
cd->SetAtom4Refs(nbr_atms,output);
} */
/* FIXME
if (!mol.HasNonZeroCoords())
{
cout << "Calcing 0D chirality "<< CorrectChirality(mol,atom)<<endl;
}
else {
//.........这里部分代码省略.........