Skip to content

Commit

Permalink
mdlvalence.h, mdlformat.cpp: Add Roger's mdlvalence patch that sets t…
Browse files Browse the repository at this point in the history
…he implicit valence at the point of reading a MOL file. This uses the MDL valence model.
  • Loading branch information
baoilleach committed Dec 11, 2012
1 parent f55f1f1 commit cf0e450
Show file tree
Hide file tree
Showing 2 changed files with 419 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/formats/mdlformat.cpp
Expand Up @@ -34,6 +34,8 @@ GNU General Public License for more details.
#include <openbabel/tokenst.h>
#include <openbabel/atomclass.h>

#include "mdlvalence.h"

using namespace std;
namespace OpenBabel
{
Expand Down Expand Up @@ -655,8 +657,24 @@ namespace OpenBabel
updown[&*bond] = bd;
}

// Apply the MDL valence model
FOR_ATOMS_OF_MOL(atom, mol) {
unsigned int elem = atom->GetAtomicNum();
int charge = atom->GetFormalCharge();
OBBondIterator i;
unsigned int count = 0;
unsigned int expval = 0;
for (OBBond* bond = atom->BeginBond(i); bond; bond = atom->NextBond(i)) {
expval += bond->GetBondOrder();
count++;
}
unsigned int impval = MDLValence(elem ,charge, expval);
atom->SetImplicitValence(impval-(expval-count));
}

mol.AssignSpinMultiplicity();
mol.EndModify();
mol.SetImplicitValencePerceived();

if (comment.length()) {
OBCommentData *cd = new OBCommentData;
Expand Down

2 comments on commit cf0e450

@egonw
Copy link

@egonw egonw commented on cf0e450 Mar 4, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noel, where is the source of this valency data?

@baoilleach
Copy link
Member Author

@baoilleach baoilleach commented on cf0e450 Mar 4, 2013 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.