/** * {@inheritDoc} */ @Override public void setAtomTypeName(String identifier) { atom.setAtomTypeName(identifier); }
/** * {@inheritDoc} */ @Override public void setAtomTypeName(String identifier) { atom.setAtomTypeName(identifier); }
private void percieveAtomTypesAndConfigureAtoms(IAtomContainer container) throws Exception { SybylAtomTypeMatcher matcher = SybylAtomTypeMatcher.getInstance(container.getBuilder()); Iterator<IAtom> atoms = container.atoms().iterator(); while (atoms.hasNext()) { IAtom atom = atoms.next(); atom.setAtomTypeName(null); IAtomType matched = matcher.findMatchingAtomType(container, atom); if (matched != null) AtomTypeManipulator.configure(atom, matched); } }
return null; else atom.setAtomTypeName(type.getAtomTypeName()); String mappedType = mapCDKToSybylType(atom); if (mappedType == null) return null;
atom.setSymbol(at.getSymbol()); atom.setAtomTypeName(at.getAtomTypeName()); atom.setFormalNeighbourCount(at.getFormalNeighbourCount()); key = "vdw" + ID;
atom.setSymbol(at.getSymbol()); atom.setAtomTypeName(at.getAtomTypeName()); atom.setFormalNeighbourCount(at.getFormalNeighbourCount()); key = "vdw" + ID;
for (int i = 0; i < mol.getAtomCount(); i++) { if (atomTypes[i] == null) { mol.getAtom(i).setAtomTypeName("UNK"); hasUnkType = true; mol.getAtom(i).setAtomTypeName(atomTypes[i]);
@Test public void unknownAtomTypeLeavesHydrogenCountAlone() throws Exception { IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); CDKHydrogenAdder hydrogenAdder = CDKHydrogenAdder.getInstance(bldr); IAtomContainer container = bldr.newInstance(IAtomContainer.class); IAtom atom = bldr.newInstance(IAtom.class, "C"); atom.setImplicitHydrogenCount(3); atom.setAtomTypeName("X"); container.addAtom(atom); hydrogenAdder.addImplicitHydrogens(container); assertThat(atom.getImplicitHydrogenCount(), is(3)); }
@Test public void unknownAtomTypeLeavesHydrogenCountAloneUnlessNull() throws Exception { IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance(); CDKHydrogenAdder hydrogenAdder = CDKHydrogenAdder.getInstance(bldr); IAtomContainer container = bldr.newInstance(IAtomContainer.class); IAtom atom = bldr.newInstance(IAtom.class, "C"); atom.setImplicitHydrogenCount(null); atom.setAtomTypeName("X"); container.addAtom(atom); hydrogenAdder.addImplicitHydrogens(container); assertThat(atom.getImplicitHydrogenCount(), is(0)); }
@Test public void roundtripAtomType() { IAtomContainer mol = new AtomContainer(); IAtom object = new Atom("C"); object.setAtomTypeName("C.sp3"); object.setFormalCharge(+1); mol.addAtom(object); Model model = Convertor.molecule2Model(mol); IAtomContainer rtMol = Convertor.model2Molecule(model, builder); String diff = AtomContainerDiff.diff(mol, rtMol); Assert.assertEquals("Unexpected diff: " + diff, 0, diff.length()); }
@Ignore @Test public void testIAtomType_Name() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); IAtom atom = builder.newInstance(IAtom.class, "C"); atom.setID("a1"); atom.setAtomTypeName("C.sp3"); mol.addAtom(atom); IAtomContainer copy = CMLRoundTripTool.roundTripMolecule(convertor, mol); String difference = AtomDiff.diff(atom, copy.getAtom(0)); Assert.assertEquals("Found non-zero diff: " + difference, 0, difference.length()); }
/** {@inheritDoc} */ @Override public IAtomType[] findMatchingAtomTypes(IAtomContainer atomContainer) throws CDKException { for (IAtom atom : atomContainer.atoms()) { IAtomType type = cdkMatcher.findMatchingAtomType(atomContainer, atom); atom.setAtomTypeName(type == null ? null : type.getAtomTypeName()); atom.setHybridization(type == null ? null : type.getHybridization()); } Aromaticity.cdkLegacy().apply(atomContainer); IAtomType[] types = new IAtomType[atomContainer.getAtomCount()]; int typeCounter = 0; for (IAtom atom : atomContainer.atoms()) { String mappedType = mapCDKToSybylType(atom); if (mappedType == null) { types[typeCounter] = null; } else { types[typeCounter] = factory.getAtomType(mappedType); } typeCounter++; } return types; }
/** * Convenience method that perceives atom types (CDK scheme) and * adds implicit hydrogens accordingly. It does not create 2D or 3D * coordinates for the new hydrogens. * * @param container to which implicit hydrogens are added. */ protected void addImplicitHydrogens(IAtomContainer container) throws Exception { CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(container.getBuilder()); int atomCount = container.getAtomCount(); String[] originalAtomTypeNames = new String[atomCount]; for (int i = 0; i < atomCount; i++) { IAtom atom = container.getAtom(i); IAtomType type = matcher.findMatchingAtomType(container, atom); originalAtomTypeNames[i] = atom.getAtomTypeName(); atom.setAtomTypeName(type.getAtomTypeName()); } CDKHydrogenAdder hAdder = CDKHydrogenAdder.getInstance(container.getBuilder()); hAdder.addImplicitHydrogens(container); // reset to the original atom types for (int i = 0; i < atomCount; i++) { IAtom atom = container.getAtom(i); atom.setAtomTypeName(originalAtomTypeNames[i]); } }
@Test public void testConfigure_IAtom() throws Exception { IAtomType atomType; IAtom atom = new org.openscience.cdk.Atom(); atom.setAtomTypeName("C.ar"); AtomTypeFactory factory = AtomTypeFactory.getInstance("org/openscience/cdk/config/data/mol2_atomtypes.xml", new ChemObject().getBuilder()); atomType = factory.configure(atom); Assert.assertNotNull(atomType); Assert.assertEquals("C", atom.getSymbol()); }
atom.setAtomTypeName((String) CDKConstants.UNSET); atom.setMaxBondOrder((IBond.Order) CDKConstants.UNSET); atom.setBondOrderSum((Double) CDKConstants.UNSET);
@Test public void testSetIsSilent() throws Exception { // because we already test that the matching get methods // return null, we only test that set does not throw // exceptions IAtom hydrogen = new ImmutableHydrogen(); hydrogen.setCharge(2.0); hydrogen.setImplicitHydrogenCount(1); hydrogen.setPoint2d(new Point2d(1, 2)); hydrogen.setPoint3d(new Point3d(2, 3, 4)); hydrogen.setStereoParity(1); hydrogen.setAtomTypeName("foo"); hydrogen.setBondOrderSum(4.0); hydrogen.setCovalentRadius(1.4); hydrogen.setFormalCharge(1); hydrogen.setFormalNeighbourCount(2); hydrogen.setHybridization(Hybridization.PLANAR3); hydrogen.setMaxBondOrder(Order.QUADRUPLE); hydrogen.setValency(4); hydrogen.setExactMass(12.0); hydrogen.setNaturalAbundance(100.0); hydrogen.setFlags(null); hydrogen.setFlag(CDKConstants.ISINRING, true); hydrogen.setID("Me"); hydrogen.addProperties(new Properties()); hydrogen.setProperties(new Properties()); hydrogen.setProperty(new String(), new String()); hydrogen.removeProperty(new String()); Assert.assertTrue(true); // to indicate we made it }
/** * @cdk.bug 2993609 */ @Test public void testSetAtoms_removeListener() { IAtomContainer ac = (IAtomContainer) newChemObject(); IAtom[] atoms = new IAtom[4]; atoms[0] = ac.getBuilder().newInstance(IAtom.class, "C"); atoms[1] = ac.getBuilder().newInstance(IAtom.class, "C"); atoms[2] = ac.getBuilder().newInstance(IAtom.class, "C"); atoms[3] = ac.getBuilder().newInstance(IAtom.class, "O"); ac.setAtoms(atoms); // if an atom changes, the atomcontainer will throw a change event too ChemObjectListenerImpl listener = new ChemObjectListenerImpl(); ac.addListener(listener); assertFalse(listener.changed); // ok, change the atom, and make sure we do get an event atoms[0].setAtomTypeName("C.sp2"); assertTrue(listener.changed); // reset the listener, overwrite the atoms, and change an old atom. // if all is well, we should not get a change event this time ac.setAtoms(new IAtom[0]); listener.reset(); // reset here, because the setAtoms() triggers a change even too assertFalse(listener.changed); // make sure the reset worked atoms[1].setAtomTypeName("C.sp2"); // make a change to an old atom assertFalse(listener.changed); // but no change event should happen }
public static void testSetAtoms_removeListener(IChemObject newChemObject) { IAtomContainer container = (IAtomContainer) newChemObject; IAtom[] atoms = new IAtom[4]; atoms[0] = container.getBuilder().newInstance(IAtom.class, "C"); atoms[1] = container.getBuilder().newInstance(IAtom.class, "C"); atoms[2] = container.getBuilder().newInstance(IAtom.class, "C"); atoms[3] = container.getBuilder().newInstance(IAtom.class, "O"); container.setAtoms(atoms); // if an atom changes, the atomcontainer will throw a change event too ChemObjectListener listener = new ChemObjectListener(); container.addListener(listener); Assert.assertFalse(listener.getChanged()); // ok, change the atom, and make sure we do get an event atoms[0].setAtomTypeName("C.sp2"); Assert.assertFalse(listener.getChanged()); // reset the listener, overwrite the atoms, and change an old atom. // if all is well, we should not get a change event this time listener.reset(); Assert.assertFalse(listener.getChanged()); // make sure the reset worked container.setAtoms(new IAtom[0]); atoms[1].setAtomTypeName("C.sp2"); // make a change to an old atom Assert.assertFalse(listener.getChanged()); // but no change event should happen } }
atom.setAtomTypeName(originalAtomtypeName); atom.setFormalNeighbourCount(originalNeighborCount); atom.setValency(originalValency);
@Test public void testAnonymise() throws Exception { IAtomContainer cyclohexane = TestMoleculeFactory.makeCyclohexane(); cyclohexane.getAtom(0).setSymbol("O"); cyclohexane.getAtom(2).setSymbol("O"); cyclohexane.getAtom(1).setAtomTypeName("remove me"); cyclohexane.getAtom(3).setFlag(CDKConstants.ISAROMATIC, true); cyclohexane.getAtom(4).setImplicitHydrogenCount(2); cyclohexane.getBond(0).setFlag(CDKConstants.SINGLE_OR_DOUBLE, true); cyclohexane.getBond(1).setFlag(CDKConstants.ISAROMATIC, true); IAtomContainer anonymous = AtomContainerManipulator.anonymise(cyclohexane); Assert.assertTrue(new UniversalIsomorphismTester().isIsomorph(anonymous, TestMoleculeFactory.makeCyclohexane())); assertThat(anonymous.getAtom(0).getSymbol(), is("C")); assertThat(anonymous.getAtom(2).getSymbol(), is("C")); assertNull(anonymous.getAtom(1).getAtomTypeName()); assertThat(anonymous.getAtom(4).getImplicitHydrogenCount(), is(0)); assertFalse(anonymous.getAtom(3).getFlag(CDKConstants.ISAROMATIC)); assertFalse(anonymous.getBond(1).getFlag(CDKConstants.ISAROMATIC)); assertFalse(anonymous.getBond(1).getFlag(CDKConstants.SINGLE_OR_DOUBLE)); }