private static void makeReferencesExplicitForMolecule(IAtomContainer molecule) { int selfCounter = 0; molecule.setProperty(prefix + ":self:" + selfCounter++, "chemical:molecularEntity"); /* * remark: this is not strictly true... the Compendium includes the ion * pair, which normally would not considered a CDK molecule */ }
private static void makeReferencesExplicitForMolecule(IAtomContainer molecule) { int selfCounter = 0; molecule.setProperty(prefix + ":self:" + selfCounter++, "chemical:molecularEntity"); /* * remark: this is not strictly true... the Compendium includes the ion * pair, which normally would not considered a CDK molecule */ }
private void setProductMolecule(IReaction IR, Collection<IAtomContainer> metabolites) { // System.out.println("-------------------"); // System.out.println("Products"); // System.out.println("-------------------"); Iterator<IAtomContainer> it = metabolites.iterator(); while (it.hasNext()) { IAtomContainer mol = it.next(); // // System.out.println("Insertion: " + mol.getID() + ", " + stoichiometryMap.get(mol.getID())); mol.setProperty("STOICHIOMETRY", stoichiometryMap.get(mol.getID())); IR.addProduct(mol, stoichiometryMap.get(mol.getID())); // standardizedReaction.setProductCoefficient(mol,stoichiometryMap.get(mol.getID())); } metabolites.clear(); stoichiometryMap.clear(); }
@Override protected void storeData() { if (inchi != null) { // cdo.setObjectProperty("Molecule", "inchi", inchi); currentMolecule.setProperty(CDKConstants.INCHI, inchi); } storeAtomData(); storeBondData(); }
@Override protected void storeData() { if (inchi != null) { // cdo.setObjectProperty("Molecule", "inchi", inchi); currentMolecule.setProperty(CDKConstants.INCHI, inchi); } storeAtomData(); storeBondData(); }
/** * Read the SMILES given in the input line - or return an empty container. * * @param line input line * @return the read container (or an empty one) */ private IAtomContainer readSmiles(final String line) { try { return sp.parseSmiles(line); } catch (CDKException e) { logger.error("Error while reading the SMILES from: " + line + ", ", e); final IAtomContainer empty = builder.newInstance(IAtomContainer.class, 0, 0, 0, 0); empty.setProperty(BAD_SMILES_INPUT, line); return empty; } }
@Test public void readNonStructuralData_wrap() throws Exception { StringBuilder sb = new StringBuilder(); sb.append("> <LONG_PROPERTY>").append('\n'); sb.append("This is a long property which should be wrapped when stored as field in an SDF D"); sb.append('\n'); sb.append("ata entry"); sb.append('\n'); BufferedReader input = new BufferedReader(new StringReader(sb.toString())); IAtomContainer mock = mock(IAtomContainer.class); MDLV2000Reader.readNonStructuralData(input, mock); verify(mock).setProperty("LONG_PROPERTY", "This is a long property which should be wrapped when stored as field in an SDF Data entry"); }
public void invert(IAtomContainer ac) { if (this.shouldInvert && ac.getProperty((Object)"Coordinates Inverted") == null || !((Boolean)ac.getProperty((Object)"Coordinates Inverted"))) { for (IAtom atom : ac.atoms()) { atom.getPoint2d().y *= -1.0; } ac.setProperty((Object)"Coordinates Inverted", (Object)Boolean.TRUE); } this.shouldInvert = false; }
/** * * @param ac */ public void invert(IAtomContainer ac) { if (shouldInvert && ac.getProperty(INVERTED) == null || !((Boolean)ac.getProperty(INVERTED))) { for (IAtom atom : ac.atoms()) { atom.getPoint2d().y *= - 1; } ac.setProperty(INVERTED, TRUE); } shouldInvert = false; }
@Test public void testPropertyOutput_two() throws CDKException, IOException { IAtomContainer adenine = TestMoleculeFactory.makeAdenine(); StringWriter sw = new StringWriter(); SDFWriter sdf = new SDFWriter(sw, Collections.singleton("two")); adenine.setProperty("one", "a"); adenine.setProperty("two", "b"); sdf.write(adenine); sdf.close(); String out = sw.toString(); assertTrue(out.contains("> <two>")); assertFalse(out.contains("> <one>")); }
@Test public void testPropertyOutput_one() throws CDKException, IOException { IAtomContainer adenine = TestMoleculeFactory.makeAdenine(); StringWriter sw = new StringWriter(); SDFWriter sdf = new SDFWriter(sw, Collections.singleton("one")); adenine.setProperty("one", "a"); adenine.setProperty("two", "b"); sdf.write(adenine); sdf.close(); String out = sw.toString(); assertTrue(out.contains("> <one>")); assertFalse(out.contains("> <two>")); }
@Test public void testPropertyOutput_All() throws CDKException, IOException { IAtomContainer adenine = TestMoleculeFactory.makeAdenine(); StringWriter sw = new StringWriter(); SDFWriter sdf = new SDFWriter(sw); adenine.setProperty("one", "a"); adenine.setProperty("two", "b"); sdf.write(adenine); sdf.close(); String out = sw.toString(); assertTrue(out.contains("> <one>")); assertTrue(out.contains("> <two>")); }
@Test public void testPropertyOutput_none() throws CDKException, IOException { IAtomContainer adenine = TestMoleculeFactory.makeAdenine(); StringWriter sw = new StringWriter(); SDFWriter sdf = new SDFWriter(sw, Collections.<String> emptySet()); adenine.setProperty("one", "a"); adenine.setProperty("two", "b"); sdf.write(adenine); sdf.close(); String out = sw.toString(); assertFalse(out.contains("> <two>")); assertFalse(out.contains("> <one>")); } }
@Test public void invalidSDfileHeaderTags() throws Exception { StringWriter writer = new StringWriter(); SDFWriter sdfWriter = new SDFWriter(writer); IAtomContainer molecule = new AtomContainer(); molecule.addAtom(new Atom("C")); molecule.setProperty("http://not-valid.com", "URL"); sdfWriter.write(molecule); sdfWriter.close(); Assert.assertThat(writer.toString(), Matchers.containsString("> <http://not_valid_com>")); }
@Test public void testSgroupAtomListWrapping() throws Exception { IAtomContainer mol = TestMoleculeFactory.makeEthylPropylPhenantren(); Sgroup sgroup = new Sgroup(); for (IAtom atom : mol.atoms()) sgroup.addAtom(atom); mol.setProperty(CDKConstants.CTAB_SGROUPS, Collections.singletonList(sgroup)); StringWriter sw = new StringWriter(); try (MDLV2000Writer mdlw = new MDLV2000Writer(sw)) { mdlw.write(mol); String output = sw.toString(); assertThat(output, containsString("M SAL 1 15")); assertThat(output, containsString("M SAL 1 4")); } }
@Test public void testWrite_IAtomContainerSet_Properties() throws Exception { StringWriter writer = new StringWriter(); IAtomContainerSet molSet = new AtomContainerSet(); IAtomContainer molecule = new AtomContainer(); molecule.addAtom(new Atom("C")); molecule.setProperty("foo", "bar"); molSet.addAtomContainer(molecule); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.write(molSet); sdfWriter.close(); Assert.assertTrue(writer.toString().indexOf("<foo>") != -1); Assert.assertTrue(writer.toString().indexOf("bar") != -1); }
@Test public void testWrite_IAtomContainerSet_CDKProperties() throws Exception { StringWriter writer = new StringWriter(); IAtomContainerSet molSet = new AtomContainerSet(); IAtomContainer molecule = new AtomContainer(); molecule.addAtom(new Atom("C")); molecule.setProperty(InvPair.CANONICAL_LABEL, "bar"); molSet.addAtomContainer(molecule); SDFWriter sdfWriter = new SDFWriter(writer); sdfWriter.write(molSet); sdfWriter.close(); Assert.assertTrue(writer.toString().indexOf(InvPair.CANONICAL_LABEL) == -1); }
@Test public void testInChI() throws Exception { IAtomContainer mol = new AtomContainer(); String inchi = "InChI=1/CH2O2/c2-1-3/h1H,(H,2,3)"; mol.setProperty(CDKConstants.INCHI, inchi); IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, mol); Assert.assertNotNull(roundTrippedMol); Assert.assertEquals(inchi, roundTrippedMol.getProperty(CDKConstants.INCHI)); }
@Test public void testDescriptorValue() throws Exception { IAtomContainer molecule = TestMoleculeFactory.makeBenzene(); String[] propertyName = {"testKey1", "testKey2"}; String[] propertyValue = {"testValue1", "testValue2"}; for (int i = 0; i < propertyName.length; i++) molecule.setProperty(propertyName[i], propertyValue[i]); IAtomContainer roundTrippedMol = CMLRoundTripTool.roundTripMolecule(convertor, molecule); for (int i = 0; i < propertyName.length; i++) { Assert.assertNotNull(roundTrippedMol.getProperty(propertyName[i])); Assert.assertEquals(propertyValue[i], roundTrippedMol.getProperty(propertyName[i])); } }
@Test public void dontOverwriteExistingSgroups() throws Exception { Abbreviations factory = new Abbreviations(); factory.add("*CCC Bu"); IAtomContainer mol = smi("c1ccccc1CCC"); Sgroup sgroup = new Sgroup(); sgroup.addAtom(mol.getAtom(6)); sgroup.addAtom(mol.getAtom(7)); sgroup.addAtom(mol.getAtom(8)); sgroup.setType(SgroupType.CtabAbbreviation); sgroup.setSubscript("n-Bu"); mol.setProperty(CDKConstants.CTAB_SGROUPS, Collections.singletonList(sgroup)); List<Sgroup> sgroups = factory.generate(mol); assertThat(sgroups.size(), is(0)); }