本文整理汇总了C++中OBAtom::SetAtomicNum方法的典型用法代码示例。如果您正苦于以下问题:C++ OBAtom::SetAtomicNum方法的具体用法?C++ OBAtom::SetAtomicNum怎么用?C++ OBAtom::SetAtomicNum使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBAtom
的用法示例。
在下文中一共展示了OBAtom::SetAtomicNum方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ReadPQS_geom
int ReadPQS_geom(istream &ifs, OBMol &mol, const char *title,
int input_style, double bohr_to_angstrom)
{
int atom_count=0;
double x, y, z;
char buffer[BUFF_SIZE];
string str;
OBAtom *atom;
vector<string> vs;
mol.Clear();
mol.BeginModify();
while (ifs.getline(buffer,BUFF_SIZE) && !card_found(buffer))
{
if (buffer[0]!='$')
{
tokenize(vs, buffer);
if (vs.size() < 1) return false; // timvdm 18/06/2008
atom=mol.NewAtom();
str=vs[0];
if (input_style==0)
{
if (vs.size() < 4) return false; // timvdm 18/06/2008
atom->SetAtomicNum(OBElements::GetAtomicNum(str.c_str()));
x=atof((char*) vs[1].c_str())*bohr_to_angstrom;
y=atof((char*) vs[2].c_str())*bohr_to_angstrom;
z=atof((char*) vs[3].c_str())*bohr_to_angstrom;
}
else
{
if (vs.size() < 5) return false; // timvdm 18/06/2008
str.replace (0,2,"");
atom->SetAtomicNum(OBElements::GetAtomicNum(str.c_str()));
x=atof((char*) vs[2].c_str())*bohr_to_angstrom;
y=atof((char*) vs[3].c_str())*bohr_to_angstrom;
z=atof((char*) vs[4].c_str())*bohr_to_angstrom;
}
atom->SetVector(x, y, z);
atom_count++;
}
}
mol.ConnectTheDots();
mol.PerceiveBondOrders();
mol.EndModify();
mol.SetTitle(title);
return atom_count;
}
示例2: basicExportTest
/* FUNCTION: basicExportTest */
void OpenBabelImportExportTest::basicExportTest() {
// Create a water molecule for frame 0
//
int frameSetId = entityManager->addFrameSet();
int frameIndex = entityManager->addFrame(frameSetId);
NXMoleculeSet* rootMoleculeSet =
entityManager->getRootMoleculeSet(frameSetId, frameIndex);
OBMol* molecule = rootMoleculeSet->newMolecule();
OBAtom* atomO = molecule->NewAtom();
atomO->SetAtomicNum(etab.GetAtomicNum("O")); // Oxygen
atomO->SetVector(0.00000000, 0.00000000, 0.37000000); // Angstroms
OBAtom* atomH1 = molecule->NewAtom();
atomH1->SetAtomicNum(etab.GetAtomicNum("H")); // Hydrogen
atomH1->SetVector(0.78000000, 0.00000000, -0.18000000);
OBAtom* atomH2 = molecule->NewAtom();
atomH2->SetAtomicNum(etab.GetAtomicNum("H")); // Hydrogen
atomH2->SetVector(-0.78000000, 0.00000000, -0.18000000);
OBBond* bond = molecule->NewBond();
bond->SetBegin(atomO);
bond->SetEnd(atomH1);
bond = molecule->NewBond();
bond->SetBegin(atomO);
bond->SetEnd(atomH2);
// Write it with the OpenBabelImportExport plugin
NXCommandResult* commandResult =
entityManager->exportToFile("testOpenBabel.pdb", frameSetId, -1);
if (commandResult->getResult() != NX_CMD_SUCCESS)
printf("\n%s\n", qPrintable(GetNV1ResultCodeString(commandResult)));
CPPUNIT_ASSERT(commandResult->getResult() == NX_CMD_SUCCESS);
}
示例3: ReadFeat
bool ReadFeat(istream &ifs,OBMol &mol, const char *title)
{
char buffer[BUFF_SIZE];
int i,natoms;
ifs.getline(buffer,BUFF_SIZE);
sscanf(buffer,"%d",&natoms);
mol.ReserveAtoms(natoms);
mol.BeginModify();
if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
mol.SetTitle(buffer);
double x,y,z;
char type[20];
OBAtom *atom;
for (i = 0; i < natoms;i++)
{
if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
sscanf(buffer,"%s %lf %lf %lf",
type,
&x,
&y,
&z);
CleanAtomType(type);
atom = mol.NewAtom();
atom->SetVector(x,y,z);
atom->SetAtomicNum(etab.GetAtomicNum(type));
}
mol.EndModify();
return(true);
}
示例4: EndElement
bool PubChemFormat::EndElement(const string& name)
{
unsigned int i;
if(name=="PC-Atoms")
{
for(i=0;i<AtNum.size();++i)
{
OBAtom* pAtom = _pmol->NewAtom();
pAtom->SetAtomicNum(AtNum[i]);
}
}
else if(name=="PC-Bonds")
{
for(i=0;i<BondBeginAtIndx.size();++i)
_pmol->AddBond(BondBeginAtIndx[i],BondEndAtIndx[i],BondOrder[i]);
}
else if(name=="PC-Conformer")
{
++ConformerIndx;
if(Coordz.size()!=Coordx.size())
Coordz.resize(Coordx.size());
for(i=0;i<CoordIndx.size();++i)
{
OBAtom* pAtom = _pmol->GetAtom(CoordIndx[i]);
pAtom->SetVector(Coordx[i],Coordy[i],Coordz[i]);
}
}
else if(name=="PC-Compound") //this is the end of the molecule we are extracting
{
_pmol->EndModify();
return false;//means stop parsing
}
return true;
}
示例5: ReadCoordinates
/**
Method reads coordinates from input stream (ifs) and
writes it into supplied OBMol object (molecule).
Input stream must be set to begining of coordinates
table in nwo file. (Line after "Output coordinates...")
Stream will be set at next line after geometry table.
If one of input arguments is NULL method returns without
any changes
If "molecule" already contain geometry - method will write
new geometry as conformer.
If "molecule" contain geometry which incompatible with read
data method returns without changes.
*/
void NWChemOutputFormat::ReadCoordinates(istream* ifs, OBMol* molecule)
{
if ((molecule == NULL) || (ifs == NULL))
return;
vector<string> vs;
char buffer[BUFF_SIZE];
double x, y, z;
unsigned int natoms = molecule->NumAtoms();
bool from_scratch = false;
double* coordinates;
if (natoms == 0)
from_scratch = true;
else
coordinates = new double[3*natoms];
ifs->getline(buffer,BUFF_SIZE); // blank
ifs->getline(buffer,BUFF_SIZE); // column headings
ifs->getline(buffer,BUFF_SIZE); // ---- ----- ----
ifs->getline(buffer,BUFF_SIZE);
tokenize(vs,buffer);
unsigned int i=0;
while (vs.size() == 6)
{
x = atof((char*)vs[3].c_str());
y = atof((char*)vs[4].c_str());
z = atof((char*)vs[5].c_str());
if (from_scratch)
{
// set atomic number
OBAtom* atom = molecule->NewAtom();
atom->SetAtomicNum(atoi(vs[2].c_str()));
atom->SetVector(x,y,z);
}
else
{
// check atomic number
if ((i>=natoms) || (molecule->GetAtom(i+1)->GetAtomicNum() != atoi(vs[2].c_str())))
{
delete[] coordinates;
return;
}
coordinates[i*3] = x;
coordinates[i*3+1] = y;
coordinates[i*3+2] = z;
i++;
}
if (!ifs->getline(buffer,BUFF_SIZE))
break;
tokenize(vs,buffer);
}
if (from_scratch)
{
return;
}
if (i != natoms) {
delete[] coordinates;
return;
}
molecule->AddConformer(coordinates);
}
示例6: ReadPartialCharges
/**
Method reads partial charges from input stream (ifs)
and writes them to supplied OBMol object (molecule)
Input stream must be set to begining of charges
table in nwo file. (Line after "Mulliken analysis of the total density")
Stream will be set at next line after charges table.
If reading charges failed or "molecule" contains
data incompatible with read charges then "molecule"
wont be changed.
*/
void NWChemOutputFormat::ReadPartialCharges(istream* ifs, OBMol* molecule)
{
if ((molecule == NULL) || (ifs == NULL))
return;
vector<string> vs;
char buffer[BUFF_SIZE];
bool from_scratch = false;
vector<int> charges;
vector<double> partial_charges;
unsigned int natoms = molecule->NumAtoms();
if (natoms == 0)
from_scratch = true;
ifs->getline(buffer,BUFF_SIZE); // ---- ----- ----
ifs->getline(buffer,BUFF_SIZE); // blank
ifs->getline(buffer,BUFF_SIZE); // column headings
ifs->getline(buffer,BUFF_SIZE); // ---- ----- ----
ifs->getline(buffer,BUFF_SIZE);
tokenize(vs, buffer);
// N Symbol Charge PartialCharge+Charge ShellCharges
// 0 1 2 3 4,etc
unsigned int i = 1;
while (vs.size() >= 4)
{
int charge = atoi(vs[2].c_str());
if (!from_scratch)
{
if (i > natoms)
return;
if (molecule->GetAtom(i++)->GetAtomicNum() != charge)
return;
}
else
charges.push_back(charge);
partial_charges.push_back(atof(vs[3].c_str()) - charge);
ifs->getline(buffer,BUFF_SIZE);
tokenize(vs, buffer);
}
if (from_scratch)
molecule->ReserveAtoms(partial_charges.size());
else if (partial_charges.size() != natoms)
return;
for(unsigned int j=0;j<partial_charges.size();j++)
{
OBAtom* atom;
if (from_scratch)
{
atom = molecule->NewAtom();
atom->SetAtomicNum(charges[j]);
}
else
{
atom = molecule->GetAtom(j+1);
}
atom->SetPartialCharge(partial_charges[j]);
}
}
示例7: ReadMolecule
bool AmberPrepFormat::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;
OBAtom *atom;
OBInternalCoord *coord;
vector<string> vs;
vector<OBInternalCoord*> internals;
mol.BeginModify();
while (ifs.getline(buffer,BUFF_SIZE))
{
tokenize(vs,buffer);
if (vs.size() == 10)
{
atom = mol.NewAtom();
coord = new OBInternalCoord();
if (mol.NumAtoms() > 1)
coord->_a = mol.GetAtom(atoi(vs[4].c_str()));
if (mol.NumAtoms() > 2)
coord->_b = mol.GetAtom(atoi(vs[5].c_str()));
if (mol.NumAtoms() > 3)
coord->_c = mol.GetAtom(atoi(vs[6].c_str()));
coord->_dst = atof(vs[7].c_str());
coord->_ang = atof(vs[8].c_str());
coord->_tor = atof(vs[9].c_str());
internals.push_back(coord);
atom->SetAtomicNum(etab.GetAtomicNum(vs[1].c_str()));
if (!ifs.getline(buffer,BUFF_SIZE))
break;
tokenize(vs,buffer);
}
}
if (internals.size() > 0)
InternalToCartesian(internals,mol);
if (!pConv->IsOption("b",OBConversion::INOPTIONS))
mol.ConnectTheDots();
if (!pConv->IsOption("s",OBConversion::INOPTIONS) && !pConv->IsOption("b",OBConversion::INOPTIONS))
mol.PerceiveBondOrders();
mol.EndModify();
mol.SetTitle(title);
return(true);
}
示例8: ReadMolecule
bool BallStickFormat::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();
int i,natoms;
char buffer[BUFF_SIZE];
if (!ifs.getline(buffer,BUFF_SIZE))
return(false);
if (!ifs.getline(buffer,BUFF_SIZE))
return(false);
sscanf(buffer,"%d",&natoms);
mol.ReserveAtoms(natoms);
mol.BeginModify();
double x,y,z;
OBAtom *atom;
vector<string> vs;
vector<string>::iterator j;
for (i = 1; i <= natoms;i ++)
{
if (!ifs.getline(buffer,BUFF_SIZE))
return(false);
tokenize(vs,buffer);
if (vs.size() < 4)
return(false);
if (vs[0].size() > 1)
vs[0][1] = tolower(vs[0][1]);
atom = mol.NewAtom();
x = atof((char*)vs[1].c_str());
y = atof((char*)vs[2].c_str());
z = atof((char*)vs[3].c_str());
atom->SetVector(x,y,z); //set coordinates
atom->SetAtomicNum(etab.GetAtomicNum(vs[0].c_str()));
for (j = vs.begin()+4;j != vs.end();j++)
mol.AddBond(atom->GetIdx(),atoi((char*)j->c_str()),1);
}
// clean out any remaining blank lines
while(ifs.peek() != EOF && ifs.good() &&
(ifs.peek() == '\n' || ifs.peek() == '\r'))
ifs.getline(buffer,BUFF_SIZE);
mol.EndModify();
mol.SetTitle(title);
return(true);
}
示例9: ReadAlchemy
bool ReadAlchemy(istream &ifs,OBMol &mol, const char *title)
{
int i;
int natoms,nbonds;
char buffer[BUFF_SIZE];
ifs.getline(buffer,BUFF_SIZE);
sscanf(buffer,"%d %*s %d", &natoms, &nbonds);
if (!natoms) return(false);
mol.ReserveAtoms(natoms);
ttab.SetFromType("ALC");
string str;
double x,y,z;
OBAtom *atom;
vector<string> vs;
for (i = 1; i <= natoms; i ++)
{
if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
tokenize(vs,buffer);
if (vs.size() != 6) return(false);
atom = mol.NewAtom();
x = atof((char*)vs[2].c_str());
y = atof((char*)vs[3].c_str());
z = atof((char*)vs[4].c_str());
atom->SetVector(x,y,z); //set coordinates
//set atomic number
ttab.SetToType("ATN"); ttab.Translate(str,vs[1]);
atom->SetAtomicNum(atoi(str.c_str()));
//set type
ttab.SetToType("INT"); ttab.Translate(str,vs[1]);
atom->SetType(str);
}
char bobuf[100];
string bostr;
int bgn,end,order;
for (i = 0; i < nbonds; i++)
{
if (!ifs.getline(buffer,BUFF_SIZE)) return(false);
sscanf(buffer,"%*d%d%d%s",&bgn,&end,bobuf);
bostr = bobuf; order = 1;
if (bostr == "DOUBLE") order = 2;
else if (bostr == "TRIPLE") order = 3;
else if (bostr == "AROMATIC") order = 5;
mol.AddBond(bgn,end,order);
}
mol.SetTitle(title);
return(true);
}
示例10: ReadMolecule
//------------------------------------------------------------------------------
bool OBMoldenFormat::ReadMolecule( OBBase* pOb, OBConversion* pConv )
{
OBMol* pmol = dynamic_cast< OBMol* >(pOb);
if( pmol == 0 ) return false;
istream& ifs = *pConv->GetInStream();
pmol->BeginModify();
pmol->SetDimension( 3 );
string lineBuffer;
getline( ifs, lineBuffer );
while( ifs && lineBuffer.find( "[Atoms]" ) == string::npos
&& lineBuffer.find( "[ATOMS]" ) == string::npos )
{
getline( ifs, lineBuffer );
}
if( !ifs ) return false;
//[Atoms] AU OR Angs
double factor = 1.; // Angstrom
if( lineBuffer.find( "AU" ) != string::npos ) factor = 0.529177249; // Bohr
while( ifs )
{
getline( ifs, lineBuffer );
if( lineBuffer.size() == 0 ) continue;
if( lineBuffer.find( '[' ) != string::npos ) break;
istringstream is( lineBuffer );
string atomName;
int atomId;
int atomicNumber;
double x, y, z;
is >> atomName >> atomId >> atomicNumber >> x >> y >> z;
OBAtom* atom = pmol->NewAtom();
if( !atom ) break;
atom->SetAtomicNum( atomicNumber );
atom->SetVector( x * factor, y * factor, z * factor );
}
if( !pConv->IsOption( "b", OBConversion::INOPTIONS ) ) pmol->ConnectTheDots();
if (!pConv->IsOption( "s", OBConversion::INOPTIONS )
&& !pConv->IsOption( "b", OBConversion::INOPTIONS ) )
{
pmol->PerceiveBondOrders();
}
pmol->EndModify();
return true;
}
示例11: ReadBiosymCAR
bool ReadBiosymCAR(istream &ifs,OBMol &mol, const char *title)
{
char buffer[BUFF_SIZE];
string str;
double x,y,z;
OBAtom *atom;
vector<string> vs;
mol.BeginModify();
while (ifs.getline(buffer,BUFF_SIZE))
{
if(strstr(buffer,"PBC") != NULL)
{
if(strstr(buffer,"ON") != NULL)
{
ifs.getline(buffer,BUFF_SIZE);
ifs.getline(buffer,BUFF_SIZE);
ifs.getline(buffer,BUFF_SIZE);
}
else
{
ifs.getline(buffer,BUFF_SIZE);
ifs.getline(buffer,BUFF_SIZE);
}
break;
}
}
while (ifs.getline(buffer,BUFF_SIZE))
{
if(strstr(buffer,"end") != NULL)
break;
atom = mol.NewAtom();
tokenize(vs,buffer);
atom->SetAtomicNum(etab.GetAtomicNum(vs[7].c_str()));
x = atof((char*)vs[1].c_str());
y = atof((char*)vs[2].c_str());
z = atof((char*)vs[3].c_str());
atom->SetVector(x,y,z);
}
mol.EndModify();
mol.ConnectTheDots();
mol.PerceiveBondOrders();
mol.SetTitle(title);
return(true);
}
示例12: ReadHIN
bool ReadHIN(istream &ifs,OBMol &mol, const char *title)
{
// Right now only read in the first molecule
int i;
int max, bo;
char buffer[BUFF_SIZE];
string str,str1;
double x,y,z;
OBAtom *atom;
vector<string> vs;
ifs.getline(buffer, BUFF_SIZE);
while (strstr(buffer,"mol") == NULL)
ifs.getline(buffer, BUFF_SIZE);
ifs.getline(buffer, BUFF_SIZE);
mol.BeginModify();
while (strstr(buffer,"endmol") == NULL)
{
tokenize(vs,buffer); // Don't really know how long it'll be
if (vs.size() < 11) break;
atom = mol.NewAtom();
atom->SetAtomicNum(etab.GetAtomicNum(vs[3].c_str()));
x = atof((char*)vs[7].c_str());
y = atof((char*)vs[8].c_str());
z = atof((char*)vs[9].c_str());
atom->SetVector(x,y,z);
max = 11 + 2 * atoi((char *)vs[10].c_str());
for (i = 11; i < max; i+=2)
{
switch(((char*)vs[i+1].c_str())[0]) // First char in next token
{
case 's': bo = 1; break;
case 'd': bo = 2; break;
case 't': bo = 3; break;
case 'a': bo = 5; break;
default : bo = 1; break;
}
mol.AddBond(mol.NumAtoms(), atoi((char *)vs[i].c_str()), bo);
}
ifs.getline(buffer, BUFF_SIZE);
}
mol.EndModify();
mol.SetTitle(title);
return(true);
}
示例13: testIdsAddAtom
void testIdsAddAtom()
{
OBMol mol;
// add 5 atoms
for (int i = 0; i < 5; ++i)
mol.NewAtom();
OBAtom a;
a.SetAtomicNum(6);
// add a sixth atom
mol.AddAtom(a);
OB_REQUIRE( mol.NumAtoms() == 6 );
OB_REQUIRE( mol.GetAtomById(5) );
OB_REQUIRE( mol.GetAtomById(5)->GetId() == 5 );
}
示例14: DeleteExpandedAtoms
void AliasData::DeleteExpandedAtoms(OBMol& mol)
{
//The atom that carries the AliasData object remains as an Xx atom with no charge;
//the others are deleted. All the attached hydrogens are also deleted.
for(unsigned i=0;i<_expandedatoms.size();++i)
{
OBAtom* at = mol.GetAtomById(_expandedatoms[i]);
if(!at)
continue;
mol.DeleteHydrogens(at);
if(at->HasData(AliasDataType))
{
at->SetAtomicNum(0);
at->SetFormalCharge(0);
at->SetSpinMultiplicity(0);
}
else
mol.DeleteAtom(at);
}
_expandedatoms.clear();
}
示例15: ReadMolecule
bool MacroModFormat::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* defaultTitle = pConv->GetTitle();
// Get Title
char buffer[BUFF_SIZE];
int natoms;
vector<vector<pair<int,int> > > connections;
if (ifs.getline(buffer,BUFF_SIZE))
{
vector<string> vs;
tokenize(vs,buffer," \n");
if ( !vs.empty() && vs.size() > 0)
sscanf(buffer,"%i%*s",&natoms);
if (natoms == 0)
return false;
if ( !vs.empty() && vs.size() > 1)
mol.SetTitle(vs[1]);
else
{
string s = defaultTitle;
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++)
//.........这里部分代码省略.........