Permalink
Browse files

mdlvalence.h, mdlformat.cpp: Add Roger's mdlvalence patch that sets t…

…he implicit valence at the point of reading a MOL file. This uses the MDL valence model.
  • Loading branch information...
1 parent f55f1f1 commit cf0e450b2462eeaa7074d297adb56f9e2b57e2a3 @baoilleach baoilleach committed Dec 11, 2012
Showing with 419 additions and 0 deletions.
  1. +18 −0 src/formats/mdlformat.cpp
  2. +401 −0 src/formats/mdlvalence.h
@@ -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
{
@@ -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;
Oops, something went wrong. Retry.

2 comments on commit cf0e450

@egonw
egonw commented on cf0e450 Mar 4, 2013

Noel, where is the source of this valency data?

@baoilleach
Member
Please sign in to comment.