/** * Create a new CDK {@link IAtom} from the Beam Atom. If the element is * unknown (i.e. '*') then an pseudo atom is created. * * @param atom an Atom from the Beam Graph * @return the CDK atom to have it's properties set */ IAtom newCDKAtom(Atom atom) { Element element = atom.element(); boolean unknown = element == Element.Unknown; if (unknown) { IPseudoAtom pseudoAtom = builder.newInstance(IPseudoAtom.class, element.symbol()); pseudoAtom.setSymbol(element.symbol()); pseudoAtom.setLabel(atom.label()); return pseudoAtom; } return createAtom(element); }
/** * Test correct output of R-groups, using the hash (#) and a separate RGP line. */ @Test public void testRGPLine() throws Exception { StringWriter writer = new StringWriter(); IAtomContainer molecule = builder.newInstance(IAtomContainer.class); IPseudoAtom atom1 = builder.newInstance(IPseudoAtom.class); atom1.setSymbol("R"); atom1.setLabel("R12"); IAtom atom2 = builder.newInstance(IAtom.class, "C"); IBond bond = builder.newInstance(IBond.class, atom1, atom2); IPseudoAtom atom3 = builder.newInstance(IPseudoAtom.class); atom3.setSymbol("A"); atom3.setLabel("A"); IBond bond2 = builder.newInstance(IBond.class, atom3, atom2); molecule.addAtom(atom1); molecule.addAtom(atom2); molecule.addAtom(atom3); molecule.addBond(bond); molecule.addBond(bond2); MDLV2000Writer mdlWriter = new MDLV2000Writer(writer); mdlWriter.write(molecule); mdlWriter.close(); String output = writer.toString(); Assert.assertTrue("Test for R#", -1 != output.indexOf("R#")); Assert.assertTrue("Test for RGP line", -1 != output.indexOf("M RGP 1 1 12")); }
/** * Labels the atom at the specified index with the provide label. If the * atom was not already a pseudo atom then the original atom is replaced. * * @param container structure * @param index atom index to replace * @param label the label for the atom * @see IPseudoAtom#setLabel(String) */ static void label(final IAtomContainer container, final int index, final String label) { final IAtom atom = container.getAtom(index); final IPseudoAtom pseudoAtom = atom instanceof IPseudoAtom ? (IPseudoAtom) atom : container.getBuilder() .newInstance(IPseudoAtom.class); if (atom.equals(pseudoAtom)) { pseudoAtom.setLabel(label); } else { pseudoAtom.setSymbol(label); pseudoAtom.setAtomicNumber(0); pseudoAtom.setPoint2d(atom.getPoint2d()); pseudoAtom.setPoint3d(atom.getPoint3d()); pseudoAtom.setMassNumber(atom.getMassNumber()); pseudoAtom.setFormalCharge(atom.getFormalCharge()); pseudoAtom.setValency(atom.getValency()); pseudoAtom.setLabel(label); // XXX: would be faster to track all replacements and do it all in one AtomContainerManipulator.replaceAtomByAtom(container, atom, pseudoAtom); } }
/** * Labels the atom at the specified index with the provide label. If the * atom was not already a pseudo atom then the original atom is replaced. * * @param container structure * @param index atom index to replace * @param label the label for the atom * @see IPseudoAtom#setLabel(String) */ static void label(final IAtomContainer container, final int index, final String label) { final IAtom atom = container.getAtom(index); final IPseudoAtom pseudoAtom = atom instanceof IPseudoAtom ? (IPseudoAtom) atom : container.getBuilder() .newInstance(IPseudoAtom.class); if (atom.equals(pseudoAtom)) { pseudoAtom.setLabel(label); } else { pseudoAtom.setSymbol(label); pseudoAtom.setAtomicNumber(0); pseudoAtom.setPoint2d(atom.getPoint2d()); pseudoAtom.setPoint3d(atom.getPoint3d()); pseudoAtom.setMassNumber(atom.getMassNumber()); pseudoAtom.setFormalCharge(atom.getFormalCharge()); pseudoAtom.setValency(atom.getValency()); pseudoAtom.setLabel(label); // XXX: would be faster to track all replacements and do it all in one AtomContainerManipulator.replaceAtomByAtom(container, atom, pseudoAtom); } }