/** * Constructs an array of Bond objects from an AtomContainer. * @param container The original AtomContainer. * @return The array of Bond objects. */ public static IBond[] getBondArray(IAtomContainer container) { IBond[] ret = new IBond[container.getBondCount()]; for (int i = 0; i < ret.length; ++i) ret[i] = container.getBond(i); return ret; }
@Test public void geometric_mismatch_opposite() { IAtomContainer query = but2ene(); IAtomContainer target = but2ene(); query.addStereoElement(new DoubleBondStereochemistry(query.getBond(0), new IBond[]{query.getBond(1), query.getBond(2)}, IDoubleBondStereochemistry.Conformation.OPPOSITE)); target.addStereoElement(new DoubleBondStereochemistry(target.getBond(0), new IBond[]{target.getBond(1), target.getBond(2)}, IDoubleBondStereochemistry.Conformation.TOGETHER)); assertFalse(new StereoMatch(query, target).apply(new int[]{0, 1, 2, 3})); }
IBond addBond(IAtom atom, IBond bond) { if (atom.equals(bond.getBegin())) { mol.addBond(bond); bond = mol.getBond(mol.getBondCount() - 1); } LocalNbrs nbrs = local.get(atom); if (nbrs == null) local.put(atom, nbrs = new LocalNbrs(false)); nbrs.bonds.add(bond); return bond; }
private int bondOrderBioType(int bidx) { IBond bond = mol.getBond(bidx); if (bond.getAtomCount() != 2) return 0; final int a1 = mol.indexOf(bond.getBegin()), a2 = mol.indexOf(bond.getEnd()); if (maskAro[a1] && maskAro[a2]) return -1; return bondOrder[bidx]; }
public IAtomContainer removeLoopBonds(IAtomContainer molecule, int position) { for (int i = 0; i < molecule.getBondCount(); i++) { IBond bond = molecule.getBond(i); if (bond.getBegin().equals(bond.getEnd())) { System.out.println("Loop found! Molecule:" + position); molecule.removeBond(bond); } } return molecule; }
@Test public void testGetRelevantReaction_IReactionSet_IBond() { Iterator<IAtomContainer> atomContainers = ReactionSetManipulator.getAllAtomContainers(set).iterator(); while (atomContainers.hasNext()) { IAtomContainer container = atomContainers.next(); IBond aBond = container.getBond(0); Assert.assertEquals(set.getReaction(0), ReactionSetManipulator.getRelevantReaction(set, aBond)); } }
private IBond getBond(int i) { if (molecule.getBondCount() <= i) { molecule.addBond(molecule.getBuilder().newInstance(IBond.class)); } return molecule.getBond(i); }
@Test public void testConstructor() { DoubleBondStereochemistry stereo = new DoubleBondStereochemistry(molecule.getBond(1), ligands, Conformation.OPPOSITE); Assert.assertNotNull(stereo); }
/** * clean the flags CDKConstants.REACTIVE_CENTER from the molecule. * * @param ac */ private void cleanFlagReactiveCenter(IAtomContainer ac) { for (int j = 0; j < ac.getAtomCount(); j++) ac.getAtom(j).setFlag(CDKConstants.REACTIVE_CENTER, false); for (int j = 0; j < ac.getBondCount(); j++) ac.getBond(j).setFlag(CDKConstants.REACTIVE_CENTER, false); } }
@Test public void testGetCIPChirality_DoubleBond_Opposite() throws Exception { IAtomContainer container = new SmilesParser(SilentChemObjectBuilder.getInstance()).parseSmiles("CCC(C)=C(C)CC"); CIP_CHIRALITY label = CIPTool.getCIPChirality( container, new DoubleBondStereochemistry(container.getBond(container.getAtom(2), container.getAtom(4)), new IBond[]{container.getBond(container.getAtom(2), container.getAtom(3)), container.getBond(container.getAtom(4), container.getAtom(6))}, IDoubleBondStereochemistry.Conformation.OPPOSITE)); assertThat(label, is(CIPTool.CIP_CHIRALITY.Z)); }
@Test public void testFixedHydrogens() throws CDKException { InChIToStructure parser = new InChIToStructure("InChI=1/CH2O2/c2-1-3/h1H,(H,2,3)/f/h2H", DefaultChemObjectBuilder.getInstance()); IAtomContainer container = parser.getAtomContainer(); assertNotNull(container); Assert.assertEquals(3, container.getAtomCount()); Assert.assertEquals(2, container.getBondCount()); assertTrue(container.getBond(0).getOrder() == Order.DOUBLE || container.getBond(1).getOrder() == Order.DOUBLE); }
@Test public void testPyrrole() throws CDKException { IAtomContainer mol = sp.parseSmiles("c1c[nH]cc1"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); atasc.decideBondOrder(mol, true); Assert.assertEquals(mol.getAtom(1).getHybridization(), IAtomType.Hybridization.SP2); Assert.assertEquals(IBond.Order.DOUBLE, mol.getBond(0).getOrder()); Assert.assertEquals(IBond.Order.SINGLE, mol.getBond(1).getOrder()); Assert.assertEquals(IBond.Order.SINGLE, mol.getBond(2).getOrder()); Assert.assertEquals(IBond.Order.DOUBLE, mol.getBond(3).getOrder()); Assert.assertEquals(IBond.Order.SINGLE, mol.getBond(4).getOrder()); }
@Test public void testBondAromatic() throws Exception { String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2'/><bondArray atomRef1='a1' atomRef2='a2' order='A'/></molecule>"; IChemFile chemFile = parseCMLString(cmlString); IAtomContainer mol = checkForSingleMoleculeFile(chemFile); Assert.assertEquals(2, mol.getAtomCount()); Assert.assertEquals(1, mol.getBondCount()); org.openscience.cdk.interfaces.IBond bond = mol.getBond(0); Assert.assertEquals(Order.SINGLE, bond.getOrder()); Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); }
/** * A unit test for JUnit with n,n-dimethyl ethylendiamine */ @Test public void testCalculateBondPolarizability_IAtomContainer_IBond() throws Exception { Polarizability pol = new Polarizability(); SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("NCCN(C)(C)"); double result = pol.calculateBondPolarizability((IAtomContainer) mol, mol.getBond(0)); Assert.assertFalse(Double.isNaN(result)); }
@Test public void testBondAromatic() throws Exception { String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2'/><bondArray atomRef1='a1' atomRef2='a2' order='A'/></molecule>"; IChemFile chemFile = parseCMLString(cmlString); IAtomContainer mol = checkForSingleMoleculeFile(chemFile); Assert.assertEquals(2, mol.getAtomCount()); Assert.assertEquals(1, mol.getBondCount()); org.openscience.cdk.interfaces.IBond bond = mol.getBond(0); Assert.assertEquals(Order.SINGLE, bond.getOrder()); Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); }
/** * @cdk.bug 1875949 */ @org.junit.Test public void testResonanceStructure() throws Exception { String smiles = "[F+]=C-[C-]"; IAtomContainer mol = sp.parseSmiles(smiles); Assert.assertEquals(3, mol.getAtomCount()); Assert.assertEquals(IBond.Order.DOUBLE, mol.getBond(0).getOrder()); Assert.assertEquals(+1, mol.getAtom(0).getFormalCharge().intValue()); Assert.assertEquals(-1, mol.getAtom(2).getFormalCharge().intValue()); }
@Test public void testBondAromatic2() throws Exception { String cmlString = "<molecule id='m1'><atomArray atomID='a1 a2'/><bondArray><bond atomRefs='a1 a2' order='2'><bondType dictRef='cdk:aromaticBond'/></bond></bondArray></molecule>"; IChemFile chemFile = parseCMLString(cmlString); IAtomContainer mol = checkForSingleMoleculeFile(chemFile); Assert.assertEquals(2, mol.getAtomCount()); Assert.assertEquals(1, mol.getBondCount()); org.openscience.cdk.interfaces.IBond bond = mol.getBond(0); Assert.assertEquals(Order.DOUBLE, bond.getOrder()); Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); }
@Test public void testRemoveNonChiralHydrogens_StereoBond() throws Exception { IAtomContainer molecule = getChiralMolTemplate(); molecule.getBond(2).setStereo(IBond.Stereo.UP); Assert.assertEquals(8, molecule.getAtomCount()); IAtomContainer ac = AtomContainerManipulator.removeNonChiralHydrogens(molecule); Assert.assertEquals(6, ac.getAtomCount()); }
@Test public void makeEdgeTest_singleBond() { MoleculeFromSignatureBuilder builder = new MoleculeFromSignatureBuilder(SilentChemObjectBuilder.getInstance()); builder.makeGraph(); builder.makeVertex("C"); builder.makeVertex("C"); builder.makeEdge(0, 1, "C", "C", ""); IAtomContainer product = builder.getAtomContainer(); Assert.assertEquals(2, product.getAtomCount()); Assert.assertEquals(1, product.getBondCount()); Assert.assertEquals(IBond.Order.SINGLE, product.getBond(0).getOrder()); }
@Test public void testDescriptor1() throws InvalidSmilesException { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol1 = sp.parseSmiles("CC"); double value = ((DoubleResult) descriptor.calculate(mol1.getBond(0), mol1).getValue()).doubleValue(); Assert.assertEquals(0, value, 0.0000); }