Skip to content

Commit

Permalink
add bondTypes and associated tests for FragmentOnBonds()
Browse files Browse the repository at this point in the history
  • Loading branch information
greglandrum committed Nov 2, 2013
1 parent 6d936e9 commit b60b260
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Code/GraphMol/Wrap/MolOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@ namespace RDKit{
unsigned int v2=python::extract<unsigned int>(pyDummyLabels[i][1]);
(*dummyLabels)[i] = std::make_pair(v1,v2);
}

}
std::vector< Bond::BondType > *bondTypes=0;
if(pyBondTypes){
unsigned int nVs=python::extract<unsigned int>(pyBondTypes.attr("__len__")());
if(nVs!=bondIndices->size()) {
throw_value_error("bondTypes shorter than bondIndices");
}
bondTypes = new std::vector< Bond::BondType >(nVs);
for(unsigned int i=0;i<nVs;++i){
(*bondTypes)[i] = python::extract< Bond::BondType >(pyBondTypes[i]);
}
}

ROMol *res=MolFragmenter::fragmentOnBonds(mol,*bondIndices,addDummies,dummyLabels,bondTypes);
delete bondIndices;
if(dummyLabels) delete dummyLabels;
Expand Down
14 changes: 14 additions & 0 deletions Code/GraphMol/Wrap/rough_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2483,6 +2483,20 @@ def test87FragmentOnBonds(self):
smi = Chem.MolToSmiles(nm,True)
self.failUnlessEqual(smi,'[1*]C.[1*]O.[1*]CC[1*].[10*]C1CC1.[10*]C1CC([10*])C1[10*]')

m = Chem.MolFromSmiles('CCC(=O)CC(=O)C')
bis = m.GetSubstructMatches(Chem.MolFromSmarts('C=O'))
bs = []
for bi in bis:
b = m.GetBondBetweenAtoms(bi[0],bi[1])
bs.append(b.GetIdx())
bts = [Chem.BondType.DOUBLE]*len(bs)
nm = Chem.FragmentOnBonds(m,bs,bondTypes=bts)
frags = Chem.GetMolFrags(nm)
self.failUnlessEqual(len(frags),3)
smi = Chem.MolToSmiles(nm,True)
self.failUnlessEqual(smi,'[2*]=O.[3*]=C(CC)CC(=[6*])C.[5*]=O')



if __name__ == '__main__':
unittest.main()
Expand Down

0 comments on commit b60b260

Please sign in to comment.