Skip to content

Commit

Permalink
Added perception of N.sp2 and N.planar3 when SINGLE_OR_DOUBLE is used
Browse files Browse the repository at this point in the history
Change-Id: Ib2b045f6801bfd23479d89d148dae7b777067079
Signed-off-by: John May <john.wilkinsonmay@gmail.com>
  • Loading branch information
egonw committed Nov 11, 2012
1 parent b6b13ed commit 7a39faa
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/org/openscience/cdk/atomtype/CDKAtomTypeMatcher.java
Expand Up @@ -857,6 +857,17 @@ private IAtomType perceiveNitrogens(IAtomContainer atomContainer, IAtom atom) th
} else if (atomContainer.getConnectedBondsCount(atom) == 0) {
IAtomType type = getAtomType("N.sp3");
if (isAcceptable(atom, atomContainer, type)) return type;
} else if (hasOneOrMoreSingleOrDoubleBonds(atomContainer, atom)) {
int connectedAtoms = atomContainer.getConnectedAtomsCount(atom) +
(atom.getImplicitHydrogenCount() == CDKConstants.UNSET
? 0
: atom.getImplicitHydrogenCount());
if (connectedAtoms == 3) {
IAtomType type = getAtomType("N.planar3");
if (isAcceptable(atom, atomContainer, type)) return type;
}
IAtomType type = getAtomType("N.sp2");
if (isAcceptable(atom, atomContainer, type)) return type;
} else { // OK, use bond order info
IBond.Order maxBondOrder = atomContainer.getMaximumBondOrder(atom);
if (maxBondOrder == CDKConstants.BONDORDER_SINGLE) {
Expand Down
36 changes: 36 additions & 0 deletions src/test/org/openscience/cdk/atomtype/CDKAtomTypeMatcherTest.java
Expand Up @@ -2125,6 +2125,25 @@ public void fix_Ca_1() throws Exception {
assertAtomTypes(testedAtomTypes, expectedTypes, molecule);
}

@Test public void testPyrrole_SingleOrDouble() throws Exception {
String[] expectedTypes = {
"C.sp2",
"N.planar3",
"C.sp2",
"C.sp2",
"C.sp2"
};
IAtomContainer molecule = MoleculeFactory.makePyrrole();
for (IBond bond : molecule.bonds()) {
bond.setOrder(IBond.Order.UNSET);
bond.setFlag(CDKConstants.SINGLE_OR_DOUBLE, true);
}
for (IAtom atom : molecule.atoms()) {
atom.setImplicitHydrogenCount(1);
}
assertAtomTypes(testedAtomTypes, expectedTypes, molecule);
}

@Test public void testPyrroleAnion() throws Exception {
String[] expectedTypes = {
"C.sp2",
Expand Down Expand Up @@ -2272,6 +2291,23 @@ public void fix_Ca_1() throws Exception {
assertAtomTypes(testedAtomTypes, expectedTypes, molecule);
}

@Test public void testPyridine_SingleOrDouble() throws Exception {
String[] expectedTypes = {
"C.sp2",
"N.sp2",
"C.sp2",
"C.sp2",
"C.sp2",
"C.sp2"
};
IAtomContainer molecule = MoleculeFactory.makePyridine();
for (IBond bond : molecule.bonds()) {
bond.setOrder(IBond.Order.UNSET);
bond.setFlag(CDKConstants.SINGLE_OR_DOUBLE, true);
}
assertAtomTypes(testedAtomTypes, expectedTypes, molecule);
}

@Test public void testPyridineDirect() throws Exception {
String[] expectedTypes = {
"N.sp2",
Expand Down

0 comments on commit 7a39faa

Please sign in to comment.