public IRenderingElement generateElements( IAtom atom, int alignment, JChemPaintRendererModel model) { return new AtomMassSymbolElement( atom.getPoint2d().x, atom.getPoint2d().y, atom.getSymbol(), atom.getFormalCharge(), atom.getImplicitHydrogenCount(), alignment, atom.getMassNumber(), super.getAtomColor(atom, model)); }
private void convertCMLToCDKHydrogenCounts() { for (IAtom atom : currentMolecule.atoms()) { if (atom.getImplicitHydrogenCount() != null) { int explicitHCount = AtomContainerManipulator.countExplicitHydrogens(currentMolecule, atom); if (explicitHCount != 0) { atom.setImplicitHydrogenCount(atom.getImplicitHydrogenCount() - explicitHCount); } } } }
@Test public void testOverwriteStaticValues() throws Exception { IAtom hydrogen = new ImmutableHydrogen(); hydrogen.setSymbol("C"); hydrogen.setAtomicNumber(12); hydrogen.setMassNumber(13); Assert.assertEquals("H", hydrogen.getSymbol()); Assert.assertEquals(1, hydrogen.getAtomicNumber().intValue()); Assert.assertEquals(1, hydrogen.getMassNumber().intValue()); }
/** * Is an atom a hydrogen atom. * * @param atom an atom * @return the atom is a hydrogen */ private static boolean isHydrogen(IAtom atom) { if (atom.getAtomicNumber() != null) return atom.getAtomicNumber() == 1; return "H".equals(atom.getSymbol()); }
@Test public void testAtom_13CH3() { IAtom a = new Atom("13CH3"); Assert.assertEquals("C", a.getSymbol()); Assert.assertEquals((Integer) 13, a.getMassNumber()); Assert.assertEquals((Integer) 6, a.getAtomicNumber()); Assert.assertEquals((Integer) 3, a.getImplicitHydrogenCount()); Assert.assertEquals((Integer) 0, a.getFormalCharge()); Assert.assertNull(a.getPoint2d()); Assert.assertNull(a.getPoint3d()); Assert.assertNull(a.getFractionalPoint3d()); }
@Test public void testDebugAtom_String() { IAtom a = new DebugAtom("C"); Assert.assertEquals("C", a.getSymbol()); Assert.assertNull(a.getPoint2d()); Assert.assertNull(a.getPoint3d()); Assert.assertNull(a.getFractionalPoint3d()); }
private boolean isMajorIsotope(IAtom atom) { if (atom.getMassNumber() == null) return false; try { IIsotope major = Isotopes.getInstance().getMajorIsotope(atom.getSymbol()); return major != null && major.getMassNumber().equals(atom.getMassNumber()); } catch (IOException ex) { return false; } }
@Override public boolean matches(IAtom atom) { int requiredCharge = this.getFormalCharge() == null ? 0 : this.getFormalCharge(); int foundCharge = atom.getFormalCharge() == null ? 0 : atom.getFormalCharge(); return this.getSymbol().equals(atom.getSymbol()) && requiredCharge == foundCharge; };
@Test public void nullMassNumber() { IAtomContainer container = mock(IAtomContainer.class); IAtom atom = mock(IAtom.class); when(atom.getAtomicNumber()).thenReturn(6); when(atom.getMassNumber()).thenReturn(null); when(atom.getImplicitHydrogenCount()).thenReturn(0); when(atom.getFormalCharge()).thenReturn(0); AtomSymbol atomSymbol = atomGenerator.generateSymbol(container, atom, HydrogenPosition.Left, new RendererModel()); List<Shape> shapes = atomSymbol.getOutlines(); assertThat(shapes.size(), is(1)); }
@Test public void oxidanide() { IAtom a = g2c.toCDKAtom(AtomBuilder.aliphatic(Element.Oxygen).hydrogens(1).anion().build(), 1); assertThat(a.getSymbol(), is("O")); assertThat(a.getImplicitHydrogenCount(), is(1)); assertThat(a.getFormalCharge(), is(-1)); }
@Test public void testExpectedValues() throws Exception { IAtom hydrogen = new ImmutableHydrogen(); Assert.assertEquals("H", hydrogen.getSymbol()); Assert.assertEquals(1, hydrogen.getAtomicNumber().intValue()); Assert.assertEquals(1, hydrogen.getMassNumber().intValue()); }
@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)); }
private static void traverseRings(IAtomContainer mol, IAtom atom, IBond prev) { atom.setFlag(CDKConstants.VISITED, true); prev.setFlag(CDKConstants.VISITED, true); for (IBond bond : mol.getConnectedBondsList(atom)) { IAtom nbr = bond.getOther(atom); if (!nbr.getFlag(CDKConstants.VISITED)) traverseRings(mol, nbr, bond); else bond.setFlag(CDKConstants.VISITED, true); } }
static IAtom atom(String symbol, int hCount, double x, double y) { IAtom a = new Atom(symbol); a.setImplicitHydrogenCount(hCount); a.setPoint2d(new Point2d(x, y)); return a; } }
/** * Sets the atomsToUnPlaced attribute of the ModelBuilder3D object. */ private void setAtomsToUnPlaced(IAtomContainer molecule) { for (int i = 0; i < molecule.getAtomCount(); i++) { molecule.getAtom(i).setFlag(CDKConstants.ISPLACED, false); } }
static IAtom atom(String symbol, int h, boolean arom) { IAtom a = new Atom(symbol); a.setImplicitHydrogenCount(h); a.setFlag(CDKConstants.ISAROMATIC, arom); return a; }
@Test public void methaneAtom() { IAtom a = g2c.toCDKAtom(AtomBuilder.aliphatic(Element.Carbon).hydrogens(4).build(), 4); assertThat(a.getSymbol(), is("C")); assertThat(a.getImplicitHydrogenCount(), is(4)); }
/** * Method to test the clone() method */ @Test public void testClone_HydrogenCount() throws Exception { IAtom atom = (IAtom) newChemObject(); atom.setImplicitHydrogenCount(Integer.valueOf(3)); IAtom clone = (IAtom) atom.clone(); // test cloning atom.setImplicitHydrogenCount(Integer.valueOf(4)); Assert.assertEquals(3, clone.getImplicitHydrogenCount().intValue()); }
private static boolean ringIsAromatic(IAtomContainer ring) { for (IAtom atom : ring.atoms()) { if (!atom.getFlag(CDKConstants.ISAROMATIC)) return false; } return true; }
/** @cdk.bug 1535587 */ @Test(timeout = 1000) public void testBug1535587() throws Exception { String smiles = "COC(=O)c2ccc3n([H])c1ccccc1c3(c2)"; IAtomContainer mol = load(smiles); atomtype(mol); assertAtomTypesPerceived(mol); Assert.assertEquals(18, mol.getAtomCount()); assertTrue(Aromaticity.cdkLegacy().apply(mol)); Assert.assertEquals("N", mol.getAtom(8).getSymbol()); assertTrue(mol.getAtom(8).getFlag(CDKConstants.ISAROMATIC)); }