Skip to content

Commit

Permalink
Upgrade Beam version, new features include optimised and improved bon…
Browse files Browse the repository at this point in the history
…d placement (kekulisation,double-bond direction) algorithms and title processing. Titles are now conveniently parsed in the SmilesParser.
  • Loading branch information
johnmay committed Nov 20, 2015
1 parent 8503cd5 commit 6ec91cb
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Expand Up @@ -371,12 +371,12 @@
<dependency>
<groupId>uk.ac.ebi.beam</groupId>
<artifactId>beam-core</artifactId>
<version>0.8</version>
<version>0.9</version>
</dependency>
<dependency>
<groupId>uk.ac.ebi.beam</groupId>
<artifactId>beam-func</artifactId>
<version>0.8</version>
<version>0.9</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
Expand Down
Expand Up @@ -27,6 +27,7 @@
import com.google.common.base.Joiner;
import org.junit.Assert;
import org.junit.Test;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.silent.SilentChemObjectBuilder;

import java.util.HashSet;
Expand Down Expand Up @@ -101,6 +102,16 @@ public void tetramethyltetraazatricyclooctane() throws Exception {
"N12[C@H](C)N3N([C@@H]3C)[C@H](C)N1[C@H]2C", "N12N([C@@H](C)N3N([C@H]3C)[C@H]1C)[C@H]2C");
}

@Test
public void dbStereoCanonGeneration() throws Exception {
String in = "Oc1ccc(cc1O)C(\\C([O-])=O)=c1/cc(O)\\c(cc1O)=C(/C([O-])=O)c1ccccc1";
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
final IAtomContainer mol = smipar.parseSmiles(in);
final SmilesGenerator cansmi = SmilesGenerator.absolute();
Assert.assertEquals(cansmi.create(mol),
cansmi.create(smipar.parseSmiles(cansmi.create(mol))));
}

static void test(String... inputs) throws Exception {

SmilesParser sp = new SmilesParser(SilentChemObjectBuilder.getInstance());
Expand Down
Expand Up @@ -171,7 +171,6 @@ private IAtomContainerSet readAtomContainerSet(IAtomContainerSet som) {
try {
IAtomContainer molecule = sp.parseSmiles(line);
molecule.setProperty("SMIdbNAME", name);
molecule.setProperty(CDKConstants.TITLE, name);
som.addAtomContainer(molecule);
} catch (CDKException exception) {
logger.warn("This SMILES could not be parsed: ", line);
Expand Down
Expand Up @@ -24,6 +24,7 @@

package org.openscience.cdk.smiles;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IBond;
Expand Down Expand Up @@ -147,6 +148,9 @@ IAtomContainer toAtomContainer(Graph g) {
// use directional bonds to assign bond-based stereo-specification
addDoubleBondStereochemistry(g, ac);

// title suffix
ac.setProperty(CDKConstants.TITLE, g.getTitle());

return ac;
}

Expand Down
Expand Up @@ -49,6 +49,7 @@
import static org.hamcrest.CoreMatchers.instanceOf;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.not;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -529,9 +530,24 @@ public void extendedTetrahedral_cw() throws Exception {
is(new IAtom[]{ac.getAtom(0), ac.getAtom(1), ac.getAtom(3), ac.getAtom(4)}));
}

@Test public void titleWithTab() throws Exception {
assertEquals(convert("CN1C=NC2=C1C(=O)N(C(=O)N2C)C\tcaffeine").getProperty(CDKConstants.TITLE),
"caffeine");
}

@Test public void titleWithSpace() throws Exception {
assertEquals(convert("CN1C=NC2=C1C(=O)N(C(=O)N2C)C caffeine").getProperty(CDKConstants.TITLE),
"caffeine");
}

@Test public void titleWithMultipleSpace() throws Exception {
assertEquals(convert("CN1C=NC2=C1C(=O)N(C(=O)N2C)C caffeine compound").getProperty(CDKConstants.TITLE),
"caffeine compound");
}

IAtomContainer convert(String smi) throws IOException {
BeamToCDK g2c = new BeamToCDK(SilentChemObjectBuilder.getInstance());
Graph g = Functions.expand(Graph.fromSmiles(smi));
Graph g = Graph.fromSmiles(smi);
return g2c.toAtomContainer(g);
}

Expand Down
Expand Up @@ -1199,6 +1199,18 @@ public void bug328() throws Exception {
is(canon("Clc1ccc(Cl)c2[nH]c([nH0]c21)C(F)(F)F")));
}


/**
* @see https://tech.knime.org/forum/cdk/buggy-behavior-of-molecule-to-cdk-node
*/
@Test
public void assignDbStereo() throws Exception {
String in = "C(/N)=C\\C=C\\1/N=C1";
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer mol = smipar.parseSmiles(in);
Assert.assertEquals("C(/N)=C\\C=C\\1/N=C1", SmilesGenerator.isomeric().create(mol));
}

static ITetrahedralChirality anticlockwise(IAtomContainer container, int central, int a1, int a2, int a3, int a4) {
return new TetrahedralChirality(container.getAtom(central), new IAtom[]{container.getAtom(a1),
container.getAtom(a2), container.getAtom(a3), container.getAtom(a4)},
Expand Down

0 comments on commit 6ec91cb

Please sign in to comment.