I come with another question about AtomType, in this case is about an uncharged N having 5 bonds, either 2xDouble + 1xSingle, or 1xDOUBLE + 3xSingle.
Ideally I want to add bonds to a N atom and later on ask the AtomTypeMatcher to launch an exception because that atom type is not allowed. I would like that the two ways of having N with 5 bonds would not be allowed. In the test I show below a molecule with a 5-bonded N is accepted O=N(=C)C What is the way to change this?
Can some sort of flag or global constant be used to only allow N with 3 bonds in some cases, and in other cases also allow N with 3 and 5 bonds?
public void testN() throws CDKException, IOException {
IAtom atomN = new NNAtom(Elements.NITROGEN);
IAtomType atomTypeN = new NNAtomType(Elements.NITROGEN);
AtomTypeManipulator.configure(atomN, atomTypeN);
IAtomContainer ac = atomN.getBuilder().newAtomContainer();
ac.addAtom(atomN);
ac.getAtom(0).setHydrogenCount(0);
ac.addAtom(new Atom("C"));
ac.getAtom(1).setHydrogenCount(2);
ac.addBond(0, 1, IBond.Order.DOUBLE);
ac.addAtom(new Atom("C"));
ac.getAtom(2).setHydrogenCount(3);
ac.addBond(0, 2, IBond.Order.SINGLE);
ac.addAtom(new Atom("O"));
ac.getAtom(3).setHydrogenCount(0);
ac.addBond(0, 3, IBond.Order.DOUBLE);
IAtomType type = null;
for (IAtom atom : ac.atoms()) {
type = CDKAtomTypeMatcher.getInstance(ac.getBuilder()).findMatchingAtomType(ac, atom);
AtomTypeManipulator.configure(atom, type);
Assert.assertNotNull(type);
}
SmilesGenerator sg = new SmilesGenerator();
System.out.println(sg.createSMILES(new Molecule(ac)));
}
No, there is no such flag. The CDKAtomTypeMatcher is there to recognize facts about chemistry. But nothing prohibits you from subclassing it, to have it recognize further atom types.
I am not sure what you try to do with this code:
IAtomType atomTypeN = new NNAtomType(Elements.NITROGEN);
AtomTypeManipulator.configure(atomN, atomTypeN);
but it seems to me that this is not doing you think it is.
I do not think this is a bug, but more like a feature request. Moreover, I am not sure if your use case is general enough. I would not want to patch the CDKAtomTypeMatcher for something like this anyway, and create a subclass.
But please explain me what the anticipated functionality of that flag is? Are there other special connectivity patterns you like to capture, for other elements? What have these in common? Why would you like to recognize an a 5 coordinate nitrogen in the first place, if you want to reject it later anyway? If I understand these things better, I can make a better suggestion.