本文整理汇总了C++中OBMol::EndModify方法的典型用法代码示例。如果您正苦于以下问题:C++ OBMol::EndModify方法的具体用法?C++ OBMol::EndModify怎么用?C++ OBMol::EndModify使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OBMol
的用法示例。
在下文中一共展示了OBMol::EndModify方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
}
示例2: ReadMolecule
bool GenBankFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = pOb->CastAndClear<OBMol>();
if (pmol == 0)
return false;
std::istream * in = pConv->GetInStream();
pmol->BeginModify();
std::string line;
SequenceType sequence_type = UnknownSequence;
getline( * in, line);
while (!in->eof())
{ // We have a new line in 'line'
if (!line.compare(0, 6, "LOCUS", 6) || !line.compare(0, 2, "ID ", 2))
{
if (sequence_type == GenBankFormat::UnknownSequence)
{ // attempt to determine the sequence type
if (line.find("RNA") != std::string::npos)
sequence_type = GenBankFormat::RNASequence;
else if (line.find("DNA") != std::string::npos)
sequence_type = GenBankFormat::DNASequence;
}
}
else if (!line.compare(0, 6, "DEFINITION", 6) || !line.compare(0, 2, "DE ", 2))
{
if (sequence_type == GenBankFormat::UnknownSequence)
{ // attempt to determine the sequence type
if (line.find("RNA") != std::string::npos)
sequence_type = GenBankFormat::RNASequence;
else if (line.find("DNA") != std::string::npos)
sequence_type = GenBankFormat::DNASequence;
else if (line.find("gene") != std::string::npos)
sequence_type = GenBankFormat::DNASequence;
}
if (pmol->GetTitle()[0] == 0)
{
std::string::size_type fc = line.find(' ');
while (fc != std::string::npos && strchr(" \t\n\r", line[fc]))
++ fc;
if (fc != std::string::npos)
pmol->SetTitle( & (line.c_str()[fc]) );
}
}
else if (!line.compare(0, 6, "ORIGIN", 6) || !line.compare(0, 2, "SQ ", 2))
break;
getline( * in, line);
}
if (sequence_type == GenBankFormat::UnknownSequence)
sequence_type = GenBankFormat::DNASequence;
bool rv = ReadFASTASequence(pmol, sequence_type, in,
!pConv->IsOption("b",OBConversion::INOPTIONS), !pConv->IsOption("s",OBConversion::INOPTIONS));
pmol->EndModify();
return rv;
}
示例3: 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;
}
示例4: 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;
}
示例5: 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);
}
示例6: 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);
}
示例7: ReadMolecule
bool XXXFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = pOb->CastAndClear<OBMol>();
if(pmol==NULL)
return false;
istream& ifs = *pConv->GetInStream();
pmol->BeginModify();
/** Parse the input stream and use the OpenBabel API to populate the OBMol **/
// To use an input option
if(pConv->IsOption("s",OBConversion::INOPTIONS))
{
//Code for when -as is specified
}
/* If the molecule has other than 3D coordinates for its atoms, it
is necessary to set the dimension to 0, or 2 */
int dim;
pmol->SetDimension(dim);
pmol->EndModify();
/* For multi-molecule formats, leave the input stream at the start of the
next molecule, ready for this routine to be called again.
/* Return true if ok. Returning false means discard the OBMol and stop
converting, unless the -e option is set. With a multi-molecule inputstream
this will skip the current molecule and continue with the next, if SkipObjects()
has been defined. If it has not, and continuation after errors is still required,
it is necessary to leave the input stream at the beginning of next object when
returning false;*/
return true;
}
示例8: ReadMolecule
//.........这里部分代码省略.........
vector3 origin(x, y, z);
// now three lines with the x, y, and z axes
vector<vector3> axes;
for (unsigned int i = 0; i < 3; ++i) {
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "delta", 5))
return false;
else {
tokenize(vs, buffer);
if (vs.size() != 4)
return false;
x = atof(vs[1].c_str());
y = atof(vs[2].c_str());
z = atof(vs[3].c_str());
axes.push_back(vector3(x, y, z));
}
}
// Two remaining header lines before the data:
/*
object 2 class gridconnections counts nx ny nz
object 3 class array type double rank 0 times n data follows
*/
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6))
return false;
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6))
return false;
pmol->BeginModify();
pmol->SetDimension(3);
OBGridData *gd = new OBGridData;
gd->SetAttribute("OpenDX");
// get all values as one vector<double>
char *endptr;
vector<double> values;
int n = voxels[0]*voxels[1]*voxels[2];
int line = 0;
values.reserve(n);
while (ifs.getline(buffer, BUFF_SIZE))
{
++line;
if (EQn(buffer, "attribute", 9))
break; // we're finished with reading data -- although we should probably have a voxel check in here too
tokenize(vs, buffer);
if (vs.size() == 0)
{
errorMsg << "Problem reading the OpenDX grid file: cannot"
<< " read line " << line
<< ", there does not appear to be any data in it.\n"
<< buffer << "\n";
obErrorLog.ThrowError(__FUNCTION__, errorMsg.str(), obError);
return false;
}
for (unsigned int l = 0; l < vs.size(); ++l)
{
values.push_back(strtod(static_cast<const char*>(vs[l].c_str()), &endptr));
}
}
gd->SetNumberOfPoints(voxels[0], voxels[1], voxels[2]);
gd->SetLimits(origin, axes[0], axes[1], axes[2]);
gd->SetUnit(OBGridData::ANGSTROM);
gd->SetOrigin(fileformatInput); // i.e., is this data from a file or determined by Open Babel
gd->SetValues(values); // set the values
pmol->SetData(gd); // store the grids in the OBMol
pmol->EndModify();
// Trailing control lines
/*
attribute "dep" string "positions"
object "regular positions regular connections" class field
component "positions" value 1
component "connections" value 2
component "data" value 3
*/
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "object", 6))
return false;
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "component", 9))
return false;
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "component", 9))
return false;
if (!ifs.getline(buffer, BUFF_SIZE) || !EQn(buffer, "component", 9))
return false;
// clean out any 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;
}
示例9: Apply
bool OBChemTsfm::Apply(OBMol &mol)
{
if (!_bgn.Match(mol))
return(false);
mol.BeginModify();
vector<vector<int> > mlist = _bgn.GetUMapList();
obErrorLog.ThrowError(__FUNCTION__,
"Ran OpenBabel::OBChemTransform", obAuditMsg);
if (!_vchrg.empty()) //modify charges
{
vector<vector<int> >::iterator i;
vector<pair<int,int> >::iterator j;
for (i = mlist.begin();i != mlist.end();++i)
for (j = _vchrg.begin();j != _vchrg.end();++j)
if (j->first < (signed)i->size()) { //goof proofing
OBAtom *atom = mol.GetAtom((*i)[j->first]);
int old_charge = atom->GetFormalCharge();
atom->SetFormalCharge(j->second);
int new_hcount = atom->GetImplicitHCount() + (j->second - old_charge);
if (new_hcount < 0)
new_hcount = 0;
atom->SetImplicitHCount(new_hcount);
}
}
if (!_vbond.empty()) //modify bond orders
{
OBBond *bond;
vector<vector<int> >::iterator i;
vector<pair<pair<int,int>,int> >::iterator j;
for (i = mlist.begin();i != mlist.end();++i)
for (j = _vbond.begin();j != _vbond.end();++j)
{
bond = mol.GetBond((*i)[j->first.first],(*i)[j->first.second]);
if (!bond)
{
obErrorLog.ThrowError(__FUNCTION__, "unable to find bond", obDebug);
continue;
}
unsigned int old_bond_order = bond->GetBondOrder();
bond->SetBondOrder(j->second);
for (int k = 0; k < 2; ++k) {
OBAtom* atom = k == 0 ? bond->GetBeginAtom() : bond->GetEndAtom();
int new_hcount = atom->GetImplicitHCount() - (j->second - old_bond_order);
if (new_hcount < 0)
new_hcount = 0;
atom->SetImplicitHCount(new_hcount);
}
}
}
if (!_vadel.empty() || !_vele.empty()) //delete atoms and change elements
{
vector<int>::iterator j;
vector<vector<int> >::iterator i;
if (!_vele.empty())
{
vector<pair<int,int> >::iterator k;
for (i = mlist.begin();i != mlist.end();++i)
for (k = _vele.begin();k != _vele.end();++k)
mol.GetAtom((*i)[k->first])->SetAtomicNum(k->second);
}
//make sure same atom isn't deleted twice
vector<bool> vda;
vector<OBAtom*> vdel;
vda.resize(mol.NumAtoms()+1,false);
for (i = mlist.begin();i != mlist.end();++i)
for (j = _vadel.begin();j != _vadel.end();++j)
if (!vda[(*i)[*j]])
{
vda[(*i)[*j]] = true;
vdel.push_back(mol.GetAtom((*i)[*j]));
}
vector<OBAtom*>::iterator k;
for (k = vdel.begin();k != vdel.end();++k)
mol.DeleteAtom((OBAtom*)*k);
}
mol.EndModify();
return(true);
}
示例10: ReadMolecule
bool ACRFormat::ReadMolecule(OBBase* pOb, OBConversion* pConv)
{
OBMol* pmol = pOb->CastAndClear<OBMol>();
if(pmol==NULL)
return false;
istream& ifs = *pConv->GetInStream();
pmol->BeginModify();
/** Parse the input stream and use the OpenBabel API to populate the OBMol **/
int id;
char buf[BUFF_SIZE];
int atoms, bonds, tmp;
float scale, dtmp;
bool atom_input = false, bond_input = false;
string type;
//int from, to;
double X,Y,Z;
vector<string> vs;
// read in one at a time
/* WARNING: Atom id starts from zero in Carine; not so in openbabel.
* Solution: increment atom id's */
while (true) {
ifs.getline(buf, BUFF_SIZE);
if (ifs.eof()) {
break;
}
if (sscanf(buf, "General Scale=%f\n", &dtmp)) {
scale = dtmp;
continue;
} else if (sscanf(buf, "Number of Atoms in Crystal=%d\n", &tmp)) {
atoms = tmp;
atom_input = true;
// read table column names
ifs.getline(buf, BUFF_SIZE);
continue;
} else if (sscanf(buf, "Number of Links in Crystal=%d\n", &tmp)) {
atom_input = false;
bond_input = true;
bonds = tmp;
// read table column names
ifs.getline(buf, BUFF_SIZE);
continue;
} else if ( '#' == buf[0] || '\r' == buf[0] || '\n' == buf[0] ) {
// between sections, in both windows and unix.
continue;
}
tokenize(vs, buf, " \t\r\n");
if (atom_input) {
if (vs.size() < 9) return false; // timvdm 18/06/2008
id = atoi((char*)vs[0].c_str()) + 1; // see warning above
type = vs[1];
X = atof((char*)vs[6].c_str())/scale;
Y = atof((char*)vs[7].c_str())/scale;
Z = atof((char*)vs[8].c_str())/scale;
OBAtom* a = pmol->NewAtom();
if (*(type.c_str()) != '*')
a->SetAtomicNum(etab.GetAtomicNum(type.c_str()));
a->SetVector(X,Y,Z);
} else if (bond_input) {
if (vs.size() < 2) return false; // timvdm 18/06/2008
// add to pmol
if (!pmol->AddBond(atoi((char*)vs[0].c_str()) + 1, atoi((char*)vs[1].c_str()) + 1,
1 /* bond order not specified in Carine, use PerceiveBondOrder later */))
{
obErrorLog.ThrowError(__FUNCTION__, "addition of bond between " + vs[0] + " and " + vs[1] + " failed", obError);
return false;
}
}
}
/* got sanity? */
if ( pmol->NumBonds() != bonds ) {
// then we read a different number of bonds than those promised.
obErrorLog.ThrowError(__FUNCTION__, "Number of bonds read does not match the number promised", obError);
return false;
} else if ( pmol->NumAtoms() != atoms ) {
obErrorLog.ThrowError(__FUNCTION__, "Number of atoms read does not match the number promised", obError);
return false;
}
pmol->PerceiveBondOrders();
pmol->EndModify();
return true;
}
示例11: ReadViewMol
bool ReadViewMol(istream &ifs,OBMol &mol,const char *title)
{
char buffer[BUFF_SIZE];
OBAtom *atom;
double x,y,z, border;
double factor = 1.0;
int bgn, end, order;
vector<string> vs;
bool foundTitle = false;
bool foundBonds = false;
mol.BeginModify();
while (ifs.getline(buffer,BUFF_SIZE))
{
if (strstr(buffer,"$title") != NULL)
{
if (!ifs.getline(buffer,BUFF_SIZE)) return (false);
mol.SetTitle(buffer);
foundTitle = true;
}
else if (strstr(buffer,"$coord") != NULL)
{
tokenize(vs,buffer);
if (vs.size() == 2)
factor = atof((char*)vs[1].c_str()); // conversion to angstrom
while (ifs.getline(buffer,BUFF_SIZE))
{
if (buffer[0] == '$') break;
tokenize(vs,buffer);
if (vs.size() != 4) return(false);
atom = mol.NewAtom();
x = atof((char*)vs[0].c_str()) * factor;
y = atof((char*)vs[1].c_str()) * factor;
z = atof((char*)vs[2].c_str()) * factor;
atom->SetVector(x,y,z); //set coordinates
atom->SetAtomicNum(etab.GetAtomicNum(vs[3].c_str()));
}
}
else if (strstr(buffer,"$bonds") != NULL)
{
foundBonds = true;
while (ifs.getline(buffer,BUFF_SIZE))
{
if (buffer[0] == '$') break;
sscanf(buffer,"%d %d %lf",&bgn,&end, &border);
if (border > 1.0)
order = int(border);
else
order = 1;
mol.AddBond(bgn+1,end+1,order);
}
}
else if (strstr(buffer,"$end") != NULL)
break;
} // while
mol.EndModify();
if (!foundTitle)
mol.SetTitle(title);
if (!foundBonds)
{
mol.ConnectTheDots();
mol.PerceiveBondOrders();
}
return(true);
}
示例12: ReadGeometry
//.........这里部分代码省略.........
ReadMode=SKIP;
bool ContainsZmatrix=false;
int zmatLineCount=0;
/*
cerr << "ReadGeometry got geometry list: \n";
for (vector<string>::iterator i=geomList.begin(); i !=geomList.end(); i++) {
// Alias the line
line = *i;
cerr << "line: " << line << endl;
}
*/
for (vector<string>::iterator i=geomList.begin(); i !=geomList.end(); i++) {
// Alias the line
line = *i;
//cerr << "ReadGeometry line is: " << line << endl;
// Check for commas & split with that as the separator if necessary
if (line.find(',')!=string::npos) {
tokenize(tokens, line, ",");
} else {
tokenize(tokens, line, " \t\n");
}
// Set the mode
if (line.compare(0, 4, "zmat")==0 || line.compare(0, 4, "inte")==0) {
ReadMode=ZMATRIX;
//cout << "ZMATRIX mode " << ReadMode << endl;
//cout << "tokens.size()" << tokens.size() << endl;
if (tokens.size()>1) if (IsUnits(tokens[1])) factor=Rescale(tokens[1]);
ContainsZmatrix=true;
vic.push_back((OBInternalCoord*)NULL); // OBMol indexed from 1 -- potential atom index problem
} else if (line.compare(0, 4, "coor")==0 || line.compare(0, 4, "cart")==0 ||line.compare(0, 4, "geom")==0) {
ReadMode=CARTESIAN;
//cout << "CARTESIAN mode " << ReadMode << endl;
if (tokens.size()>1) if (IsUnits(tokens[1])) factor=Rescale(tokens[1]);
/*
We need to have read the variables first
} else if (line.compare(0, 4, "vari")==0) {
ReadMode=VARIABLES;
//cout << "VARIABLES mode "<< ReadMode << endl;
if (tokens.size() == 2) factor=Rescale(tokens[1]);
//cout << "Factor now " << factor << endl;
} else if (line.compare(0, 4, "cons")==0) {
ReadMode=CONSTANTS;
//cout << "CONSTANTS mode\n";
if (tokens.size() == 2)
factor=Rescale(tokens[1]);
//cout << "Factor now " << factor << endl;
*/
} else if (line.compare(0, 3, "end")==0) {
ReadMode=SKIP;
//cout << "SKIP mode " << ReadMode << endl;
} else {
if (ReadMode==SKIP) continue;
if (ReadMode==ZMATRIX) {
// Create an atom
OBAtom *atom = mol.NewAtom();
// Read the ZMatrix definition line
if (! ReadLineZmatrix(mol,atom,tokens,factor,&zmatLineCount) )
{
errorMsg << "Problems reading a GAMESS-UK Input file: "
<< "Could not read zmat line: " << line;
obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() ,
obWarning);
return (false);
}
} // End ReadMode ZMATRIX
if (ReadMode==CARTESIAN) {
OBAtom *atom = mol.NewAtom();
if (! ReadLineCartesian(atom,tokens,factor) )
{
errorMsg << "Problems reading a GAMESS-UK Input file: "
<< "Could not read xyz line: " << line;
obErrorLog.ThrowError(__FUNCTION__, errorMsg.str() ,
obWarning);
return (false);
}
} // End ReadMode CARTESIAN
} // End Test for first chars on line
} // End loop over lines
if (ContainsZmatrix)InternalToCartesian(vic,mol);
mol.EndModify();
return true;
}
示例13: 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;
}
示例14: mol
//.........这里部分代码省略.........
{
cout << "Bail out! Cannot read file format!" << endl;
return(-1);
}
if (! conv.SetInAndOutFormats(pFormat, pFormat))
{
cout << "Bail out! File format isn't loaded" << endl;
return (-1);
}
OBMol testMol2D, testMol3D;
if (conv.Read(&testMol3D))
cout << "ok 8\n";
else
cout << "not ok 8\n";
testMol3D.Center();
// test bond insertion (PR#1665649)
OBMol doubleBondMol;
OBAtom *a1, *a2;
OBBond *b;
doubleBondMol.BeginModify();
a1 = doubleBondMol.NewAtom();
a1->SetVector(0.0, 0.0, 0.0);
a1->SetAtomicNum(6);
a2 = doubleBondMol.NewAtom();
a2->SetVector(1.6, 0.0, 0.0);
a2->SetAtomicNum(6);
b = doubleBondMol.NewBond();
b->SetBegin(a1);
b->SetEnd(a2);
a1->AddBond(b);
a2->AddBond(b);
doubleBondMol.EndModify();
cout << "ok 9" << endl;
// test AddHydrogens
OBMol testMolH;
testMolH.BeginModify();
OBAtom *testAtom = testMolH.NewAtom();
testAtom->SetVector(0.5f, 0.5f, 0.5f);
testAtom->SetAtomicNum(6);
testAtom->SetImplicitHCount(4);
testMolH.EndModify();
testMolH.AddHydrogens();
if (testMolH.NumAtoms() == 5) {
cout << "ok 10" << endl;
} else {
cout << "not ok 10" << endl;
}
// test AddHydrogens (pr #1665519)
OBMol testMolH2;
OBAtom *testAtom2 = testMolH2.NewAtom();
testAtom2->SetVector(0.5f, 0.5f, 0.5f);
testAtom2->SetAtomicNum(6);
testAtom2->SetImplicitHCount(4);
testMolH2.AddHydrogens();
if (testMolH2.NumAtoms() == 5) {
cout << "ok 11" << endl;
} else {
cout << "not ok 11 # hydrogen additions" << endl;
}
// Attempt to write an empty InChI (PR#2864334)
pFormat = conv.FindFormat("InChI");