MMFF94AtomTypeMatcher implements IAtomTypeMatcher { @Override public IAtomType findMatchingAtomType(IAtomContainer atomContainer, IAtom atomInterface) throws CDKException { if (factory == null) { try { factory = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/mmff94_atomtypes.xml", atomContainer.getBuilder()); } catch (Exception ex1) { logger.error(ex1.getMessage()); logger.debug(ex1); throw new CDKException("Could not instantiate the AtomType list!", ex1); } } IAtom atom = atomInterface; logger.debug(" Symbol:" + atom.getSymbol() + " HoseCode>" + atom.getProperty(CDKConstants.SPHERICAL_MATCHER) + " "); if (atom instanceof IPseudoAtom) { return factory.getAtomTypes("DU")[0]; } Pattern p1 = null; Pattern p2 = null; String ID = ""; boolean atomTypeFlag = false; Matcher mat1 = null; Matcher mat2 = null; IBond.Order tmpMaxBondOrder; maxBondOrder = atomContainer.getMaximumBondOrder(atom); for (int j = 0; j < atomTypeIds.length; j++) { tmpMaxBondOrder = factory.getAtomType(atomTypeIds[j]).getMaxBondOrder(); String atomSphericalMatcher = (String) factory.getAtomType(atomTypeIds[j]).getProperty( CDKConstants.SPHERICAL_MATCHER); logger.debug(j + " ATOM TYPE " + tmpMaxBondOrder + " " + atomSphericalMatcher); p1 = Pattern.compile(atomSphericalMatcher); mat1 = p1.matcher((String) atom.getProperty(CDKConstants.SPHERICAL_MATCHER)); if (mat1.matches()) { ID = atomTypeIds[j]; Object property = atom.getProperty(CDKConstants.CHEMICAL_GROUP_CONSTANT); int atomChemGroupConstant = (Integer) property; Object ringSize = atom.getProperty(CDKConstants.PART_OF_RING_OF_SIZE); int atomRingSize = -1; if (ringSize != null) { atomRingSize = (Integer) ringSize; } if (atomTypeIds[j].equals("C")) { if (atomChemGroupConstant != -1) { if (ringSize != null && maxBondOrder == IBond.Order.SINGLE) { if (atomRingSize == 3) { ID = atomTypeIds[9]; } else if (atomRingSize == 4) { ID = atomTypeIds[8]; } } else { String type13Matcher = getSphericalMatcher(atomTypeIds[13]); p1 = Pattern.compile(type13Matcher); mat1 = p1.matcher(atomSphericalMatcher); String type12Matcher = getSphericalMatcher(atomTypeIds[12]); p2 = Pattern.compile(type12Matcher); mat2 = p2.matcher(atomSphericalMatcher); if (mat1.matches() && atomChemGroupConstant % 2 == 0 && atom.getFlag(CDKConstants.ISAROMATIC) && atomRingSize == 5) { ID = atomTypeIds[13]; } else if (mat2.matches() && atomChemGroupConstant % 2 == 0 && atom.getFlag(CDKConstants.ISAROMATIC) && atomRingSize == 5) { ID = atomTypeIds[12]; } else if (atomChemGroupConstant % 2 == 0 && atom.getFlag(CDKConstants.ISAROMATIC) && atomRingSize == 5) { ID = atomTypeIds[14]; } else if (atom.getFlag(CDKConstants.ISAROMATIC)) { ID = atomTypeIds[11]; } } } else { p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[66])); mat1 = p1.matcher(atomSphericalMatcher); if (mat1.matches()) { ID = atomTypeIds[66]; } } } else if (atomTypeIds[j].equals("Csp2")) { if (atomChemGroupConstant % 2 == 0 & atomRingSize == 4 & !atom.getFlag(CDKConstants.ISAROMATIC)) { ID = atomTypeIds[10]; } } else if (atomTypeIds[j].equals("C=")) { if (atomChemGroupConstant % 2 == 0 && atom.getFlag(CDKConstants.ISAROMATIC)) { ID = atomTypeIds[12]; } } else if (atomTypeIds[j].equals("N")) { p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[48])); mat1 = p1.matcher(atomSphericalMatcher); if (mat1.matches() && atomChemGroupConstant == -1) { ID = atomTypeIds[48]; } p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[44])); mat1 = p1.matcher(atomSphericalMatcher); if (mat1.matches() && maxBondOrder == tmpMaxBondOrder) { ID = atomTypeIds[44]; } p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[56])); mat1 = p1.matcher(atomSphericalMatcher); if (atomChemGroupConstant == 10) { ID = atomTypeIds[56]; } else if (atomChemGroupConstant == 4) { ID = atomTypeIds[57]; } else if (atomChemGroupConstant % 2 == 0 & atomRingSize == 5 & atom.getFlag(CDKConstants.ISAROMATIC)) { ID = atomTypeIds[64]; } p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[61])); mat1 = p1.matcher(atomSphericalMatcher); if (mat1.matches() && maxBondOrder == tmpMaxBondOrder) { ID = atomTypeIds[43]; } if (atom.getFlag(CDKConstants.ISAROMATIC)) { if (mat1.matches() && atomChemGroupConstant == 12) { ID = atomTypeIds[61]; } else if (mat1.matches() && atomRingSize == 5) { ID = atomTypeIds[62]; } } p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[45])); mat1 = p1.matcher(getSphericalMatcher(atom)); if (mat1.matches()) { ID = atomTypeIds[45]; } } else if (atomTypeIds[j].equals("N=C")) { p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[59])); mat1 = p1.matcher(getSphericalMatcher(atom)); if (atomChemGroupConstant != -1) { if (mat1.matches() && atomChemGroupConstant % 2 == 0 && atom.getFlag(CDKConstants.ISAROMATIC) && atomRingSize == 5) { ID = atomTypeIds[59]; } else if (atomChemGroupConstant == 10) { ID = atomTypeIds[56]; } else if (atomChemGroupConstant == 4) { ID = atomTypeIds[57]; } } p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[43])); mat1 = p1.matcher(getSphericalMatcher(atom)); if (mat1.matches()) { if (atomChemGroupConstant == 10) { ID = atomTypeIds[61]; } else if (atom.getFlag(CDKConstants.ISAROMATIC) && atomRingSize == 5) { ID = atomTypeIds[62]; } else { ID = atomTypeIds[43]; } } } else if (atomTypeIds[j].equals("N2OX")) { p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[46])); mat1 = p1.matcher(getSphericalMatcher(atom)); if (mat1.matches() && atomChemGroupConstant == -1) { ID = atomTypeIds[46]; } if (atomChemGroupConstant == 12) { ID = atomTypeIds[61]; } else if (atomChemGroupConstant != -1 && atom.getFlag(CDKConstants.ISAROMATIC) && atomRingSize == 5) { ID = atomTypeIds[62]; } } else if (atomTypeIds[j].equals("=N=") || atomTypeIds[j].equals("NAZT")) { if (atomChemGroupConstant != -1 && atom.getFlag(CDKConstants.ISAROMATIC) && atomRingSize == 5) { ID = atomTypeIds[59]; } } else if (atomTypeIds[j].equals("N+=")) { if (atomChemGroupConstant != -1 && atom.getFlag(CDKConstants.ISAROMATIC) && atomRingSize == 5) { ID = atomTypeIds[63]; } else if (atomChemGroupConstant == 12) { ID = atomTypeIds[58]; } } else if (atomTypeIds[j].equals("O")) { if (atomChemGroupConstant == 6) { ID = atomTypeIds[35]; } } else if (atomTypeIds[j].equals("HO")) { p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[21])); mat1 = p1.matcher(atomSphericalMatcher); if (mat1.matches()) { ID = atomTypeIds[21]; } p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[18])); mat1 = p1.matcher(atomSphericalMatcher); if (mat1.matches()) { ID = atomTypeIds[18]; } } else if (atomTypeIds[j].equals("P")) { p1 = Pattern.compile(getSphericalMatcher(atomTypeIds[75])); mat1 = p1.matcher(atomSphericalMatcher); if (mat1.matches()) { ID = atomTypeIds[75]; } } else if (atomTypeIds[j].equals("S")) { if (atomRingSize == 5 && atom.getFlag(CDKConstants.ISAROMATIC)) { ID = atomTypeIds[72]; } } else if (atomTypeIds[j].equals("HC")) { p1 = Pattern.compile(getSphericalMatcher("HP")); mat1 = p1.matcher((String) atom.getProperty(CDKConstants.SPHERICAL_MATCHER)); if (mat1.matches()) { ID = "HP"; } } atomTypeFlag = true; logger.debug(" MATCH AtomTypeID:" + j + " " + ID); break; } } if (atomTypeFlag) { atomTypeFlag = false; return factory.getAtomType(ID); } else { return factory.getAtomType("DU"); } } MMFF94AtomTypeMatcher(); @Override IAtomType[] findMatchingAtomTypes(IAtomContainer atomContainer); @Override IAtomType findMatchingAtomType(IAtomContainer atomContainer, IAtom atomInterface);  }
@Test public void testFindMatchingAtomType_IAtomContainer_IAtom_Methanol() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); IAtom carbon = builder.newInstance(IAtom.class, Elements.CARBON); IAtom oxygen = builder.newInstance(IAtom.class, Elements.OXYGEN); mol.addAtom(carbon); mol.addAtom(oxygen); mol.addBond(builder.newInstance(IBond.class, carbon, oxygen, Order.SINGLE)); addExplicitHydrogens(mol); String[] testResult = {"C", "O", "HC", "HC", "HC", "HO"}; AtomTypeTools att = new AtomTypeTools(); MMFF94AtomTypeMatcher atm = new MMFF94AtomTypeMatcher(); att.assignAtomTypePropertiesToAtom(mol, false); for (int i = 0; i < mol.getAtomCount(); i++) { logger.debug("atomNr:" + mol.getAtom(i).toString()); IAtomType matched = atm.findMatchingAtomType(mol, mol.getAtom(i)); Assert.assertNotNull(matched); AtomTypeManipulator.configure(mol.getAtom(i), matched); } for (int i = 0; i < testResult.length; i++) { assertAtomType(testedAtomTypes, testResult[i], mol.getAtom(i)); } }
@Test @Ignore("Old atom typing method - see new Mmff class") public void testFindMatchingAtomType_IAtomContainer_IAtom_Methylamine() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); IAtom carbon = builder.newInstance(IAtom.class, Elements.CARBON); IAtom nitrogen = builder.newInstance(IAtom.class, Elements.NITROGEN); mol.addAtom(carbon); mol.addAtom(nitrogen); mol.addBond(builder.newInstance(IBond.class, carbon, nitrogen, Order.SINGLE)); addExplicitHydrogens(mol); String[] testResult = {"C", "N", "HC", "HC", "HC", "HN", "HN"}; AtomTypeTools att = new AtomTypeTools(); MMFF94AtomTypeMatcher atm = new MMFF94AtomTypeMatcher(); att.assignAtomTypePropertiesToAtom(mol, false); for (int i = 0; i < mol.getAtomCount(); i++) { logger.debug("atomNr:" + mol.getAtom(i).toString()); IAtomType matched = atm.findMatchingAtomType(mol, mol.getAtom(i)); Assert.assertNotNull(matched); AtomTypeManipulator.configure(mol.getAtom(i), matched); } for (int i = 0; i < testResult.length; i++) { assertAtomType(testedAtomTypes, testResult[i], mol.getAtom(i)); } }
@Test public void testFindMatchingAtomType_IAtomContainer_IAtom_Ethoxyethane() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); IAtom carbon = builder.newInstance(IAtom.class, Elements.CARBON); IAtom oxygen = builder.newInstance(IAtom.class, Elements.OXYGEN); IAtom carbon2 = builder.newInstance(IAtom.class, Elements.CARBON); mol.addAtom(carbon); mol.addAtom(oxygen); mol.addAtom(carbon2); mol.addBond(builder.newInstance(IBond.class, carbon, oxygen, Order.SINGLE)); mol.addBond(builder.newInstance(IBond.class, carbon2, oxygen, Order.SINGLE)); addExplicitHydrogens(mol); String[] testResult = {"C", "O", "C", "HC", "HC", "HC", "HC", "HC", "HC"}; AtomTypeTools att = new AtomTypeTools(); MMFF94AtomTypeMatcher atm = new MMFF94AtomTypeMatcher(); att.assignAtomTypePropertiesToAtom(mol, false); for (int i = 0; i < mol.getAtomCount(); i++) { logger.debug("atomNr:" + mol.getAtom(i).toString()); IAtomType matched = atm.findMatchingAtomType(mol, mol.getAtom(i)); Assert.assertNotNull(matched); AtomTypeManipulator.configure(mol.getAtom(i), matched); } for (int i = 0; i < testResult.length; i++) { assertAtomType(testedAtomTypes, testResult[i], mol.getAtom(i)); } }
@Test public void testFindMatchingAtomType_IAtomContainer_IAtom_Methanethiol() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); IAtom carbon = builder.newInstance(IAtom.class, Elements.CARBON); IAtom sulfur = builder.newInstance(IAtom.class, Elements.SULFUR); mol.addAtom(carbon); mol.addAtom(sulfur); mol.addBond(builder.newInstance(IBond.class, carbon, sulfur, Order.SINGLE)); addExplicitHydrogens(mol); String[] testResult = {"C", "S", "HC", "HC", "HC", "HP"}; AtomTypeTools att = new AtomTypeTools(); MMFF94AtomTypeMatcher atm = new MMFF94AtomTypeMatcher(); att.assignAtomTypePropertiesToAtom(mol, false); for (int i = 0; i < mol.getAtomCount(); i++) { logger.debug("atomNr:" + mol.getAtom(i).toString()); IAtomType matched = atm.findMatchingAtomType(mol, mol.getAtom(i)); Assert.assertNotNull(matched); AtomTypeManipulator.configure(mol.getAtom(i), matched); } for (int i = 0; i < testResult.length; i++) { assertAtomType(testedAtomTypes, testResult[i], mol.getAtom(i)); } }
@Test public void testFindMatchingAtomType_IAtomContainer_IAtom_Chloromethane() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); IAtom carbon = builder.newInstance(IAtom.class, Elements.CARBON); IAtom chlorine = builder.newInstance(IAtom.class, Elements.CHLORINE); mol.addAtom(carbon); mol.addAtom(chlorine); mol.addBond(builder.newInstance(IBond.class, carbon, chlorine, Order.SINGLE)); addExplicitHydrogens(mol); String[] testResult = {"C", "CL", "HC", "HC", "HC"}; AtomTypeTools att = new AtomTypeTools(); MMFF94AtomTypeMatcher atm = new MMFF94AtomTypeMatcher(); att.assignAtomTypePropertiesToAtom(mol, false); for (int i = 0; i < mol.getAtomCount(); i++) { logger.debug("atomNr:" + mol.getAtom(i).toString()); IAtomType matched = atm.findMatchingAtomType(mol, mol.getAtom(i)); Assert.assertNotNull(matched); AtomTypeManipulator.configure(mol.getAtom(i), matched); } for (int i = 0; i < testResult.length; i++) { assertAtomType(testedAtomTypes, testResult[i], mol.getAtom(i)); } }
@Test public void testFindMatchingAtomType_IAtomContainer_IAtom_Benzene() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); for (int i = 0; i < 6; i++) { IAtom carbon = builder.newInstance(IAtom.class, Elements.CARBON); carbon.setFlag(CDKConstants.ISAROMATIC, true); mol.addAtom(carbon); } IBond ringBond = builder .newInstance(IBond.class, mol.getAtom(0), mol.getAtom(1), Order.DOUBLE); ringBond.setFlag(CDKConstants.ISAROMATIC, true); mol.addBond(ringBond); ringBond = builder.newInstance(IBond.class, mol.getAtom(1), mol.getAtom(2), Order.SINGLE); ringBond.setFlag(CDKConstants.ISAROMATIC, true); mol.addBond(ringBond); ringBond = builder.newInstance(IBond.class, mol.getAtom(2), mol.getAtom(3), Order.DOUBLE); ringBond.setFlag(CDKConstants.ISAROMATIC, true); mol.addBond(ringBond); ringBond = builder.newInstance(IBond.class, mol.getAtom(3), mol.getAtom(4), Order.SINGLE); ringBond.setFlag(CDKConstants.ISAROMATIC, true); mol.addBond(ringBond); ringBond = builder.newInstance(IBond.class, mol.getAtom(4), mol.getAtom(5), Order.DOUBLE); ringBond.setFlag(CDKConstants.ISAROMATIC, true); mol.addBond(ringBond); ringBond = builder.newInstance(IBond.class, mol.getAtom(5), mol.getAtom(0), Order.SINGLE); ringBond.setFlag(CDKConstants.ISAROMATIC, true); mol.addBond(ringBond); addExplicitHydrogens(mol); String[] testResult = {"Car", "Car", "Car", "Car", "Car", "Car", "HC", "HC", "HC", "HC", "HC", "HC"}; AtomTypeTools att = new AtomTypeTools(); MMFF94AtomTypeMatcher atm = new MMFF94AtomTypeMatcher(); att.assignAtomTypePropertiesToAtom(mol, false); for (int i = 0; i < mol.getAtomCount(); i++) { logger.debug("atomNr:" + mol.getAtom(i).toString()); IAtomType matched = atm.findMatchingAtomType(mol, mol.getAtom(i)); Assert.assertNotNull(matched); AtomTypeManipulator.configure(mol.getAtom(i), matched); } for (int i = 0; i < testResult.length; i++) { assertAtomType(testedAtomTypes, testResult[i], mol.getAtom(i)); } }
@Test public void testFindMatchingAtomType_IAtomContainer_IAtom_Water() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); IAtom oxygen = builder.newInstance(IAtom.class, Elements.OXYGEN); mol.addAtom(oxygen); addExplicitHydrogens(mol); String[] testResult = {"OH2", "HO", "HO"}; AtomTypeTools att = new AtomTypeTools(); MMFF94AtomTypeMatcher atm = new MMFF94AtomTypeMatcher(); att.assignAtomTypePropertiesToAtom(mol, false); for (int i = 0; i < mol.getAtomCount(); i++) { logger.debug("atomNr:" + mol.getAtom(i).toString()); IAtomType matched = atm.findMatchingAtomType(mol, mol.getAtom(i)); Assert.assertNotNull(matched); AtomTypeManipulator.configure(mol.getAtom(i), matched); } for (int i = 0; i < testResult.length; i++) { assertAtomType(testedAtomTypes, testResult[i], mol.getAtom(i)); } }