Skip to content

Commit

Permalink
Support for @sp,@tb, and @oh configurations.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Nov 28, 2017
1 parent 0eee2c2 commit 8c9c77a
Show file tree
Hide file tree
Showing 8 changed files with 630 additions and 14 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>beam</artifactId>
<groupId>uk.ac.ebi.beam</groupId>
<version>1.0</version>
<version>1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/uk/ac/ebi/beam/Graph.java
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ void replace(Edge org, Edge rep) {
* @return whether the topology replaced an existing configuration
*/
void addTopology(Topology t) {
if (t != Topology.unknown())
if (t != null && t != Topology.unknown())
topologies[t.atom()] = t;
}

Expand All @@ -357,7 +357,7 @@ void clearTopology(int v) {
* @param u a vertex to access the topology of
* @return the topology of vertex 'u'
*/
Topology topologyOf(int u) {
public Topology topologyOf(int u) {
if (topologies[u] == null)
return Topology.unknown();
return topologies[u];
Expand Down
554 changes: 552 additions & 2 deletions core/src/main/java/uk/ac/ebi/beam/Topology.java

Large diffs are not rendered by default.

45 changes: 45 additions & 0 deletions core/src/test/java/uk/ac/ebi/beam/GraphTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -491,4 +491,49 @@ public void invalidPermutation() {
assertThat(Graph.fromSmiles("C1C[N@2]2CC[C@H]1C2").toSmiles(),
containsString("C1C[N@@]2CC[C@H]1C2"));
}

@Test public void cisplatin() throws InvalidSmilesException {
Graph g = Graph.fromSmiles("[NH3][Pt@SP1]([NH3])(Cl)Cl");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.SquarePlanar));
assertThat(g.toSmiles(), is("[NH3][Pt@SP1]([NH3])(Cl)Cl"));
assertThat(g.permute(new int[]{0, 1, 2, 4, 3}).toSmiles(),
is("[NH3][Pt@SP3]([NH3])(Cl)Cl"));
}

@Test public void trigonalBipyramidal() throws InvalidSmilesException {
Graph g = Graph.fromSmiles("S[As@TB1](F)(Cl)(Br)N");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.TrigonalBipyramidal));
assertThat(g.toSmiles(), is("S[As@](F)(Cl)(Br)N"));
assertThat(g.permute(new int[]{0, 1, 2, 4, 3, 5}).toSmiles(),
is("S[As@@](F)(Br)(Cl)N"));
}

@Test public void trigonalBipyramidal2() throws InvalidSmilesException {
Graph g = Graph.fromSmiles("S[As@TB2](F)(Cl)(Br)N");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.TrigonalBipyramidal));
assertThat(g.toSmiles(), is("S[As@@](F)(Cl)(Br)N"));
assertThat(g.permute(new int[]{0, 1, 2, 4, 3, 5}).toSmiles(),
is("S[As@](F)(Br)(Cl)N"));
}

@Test public void trigonalBipyramidal15() throws InvalidSmilesException {
Graph g = Graph.fromSmiles("F[As@TB15](Cl)(S)(Br)N");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.TrigonalBipyramidal));
assertThat(g.toSmiles(), is("F[As@TB15](Cl)(S)(Br)N"));
assertThat(g.permute(new int[]{0, 1, 2, 4, 3, 5}).toSmiles(),
is("F[As@TB17](Cl)(Br)(S)N"));
}

@Test public void octahedral1() throws InvalidSmilesException {
Graph g = Graph.fromSmiles("C[Co@](F)(Cl)(Br)(I)S");
assertThat(g.topologyOf(1).type(),
is(Configuration.Type.Octahedral));
assertThat(g.toSmiles(), is("C[Co@](F)(Cl)(Br)(I)S"));
assertThat(g.permute(new int[]{0, 1, 2, 4, 3, 5, 6}).toSmiles(),
is("C[Co@OH8](F)(Br)(Cl)(I)S"));
}
}
33 changes: 27 additions & 6 deletions core/src/test/java/uk/ac/ebi/beam/TopologyTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,20 +312,41 @@ public void create_Clockwise() {

@Test
public void create_tb() {
assertThat(Topology.create(0, new int[0], Collections
.<Edge>emptyList(), Configuration.TB1), is(Topology.unknown()));
int[] vs = new int[]{1, 2, 3, 4, 5};
List<Edge> es = Arrays.asList(new Edge(0, 1, Bond.IMPLICIT),
new Edge(0, 2, Bond.IMPLICIT),
new Edge(0, 3, Bond.IMPLICIT),
new Edge(0, 4, Bond.IMPLICIT),
new Edge(0, 5, Bond.IMPLICIT));
Topology t = Topology.create(0, vs, es, Configuration.TB5);
assertThat(t.configuration(), is(Configuration.TB5));
assertThat(t.atom(), is(0));
}

@Test
public void create_sp() {
assertThat(Topology.create(0, new int[0], Collections
.<Edge>emptyList(), Configuration.SP1), is(Topology.unknown()));
int[] vs = new int[]{1, 2, 3, 4};
List<Edge> es = Arrays.asList(new Edge(0, 1, Bond.IMPLICIT),
new Edge(0, 2, Bond.IMPLICIT),
new Edge(0, 3, Bond.IMPLICIT),
new Edge(0, 4, Bond.IMPLICIT));
Topology t = Topology.create(0, vs, es, Configuration.SP1);
assertThat(t.configuration(), is(Configuration.SP1));
assertThat(t.atom(), is(0));
}

@Test
public void create_oh() {
assertThat(Topology.create(0, new int[0], Collections
.<Edge>emptyList(), Configuration.OH1), is(Topology.unknown()));
int[] vs = new int[]{1, 2, 3, 4, 5, 6};
List<Edge> es = Arrays.asList(new Edge(0, 1, Bond.IMPLICIT),
new Edge(0, 2, Bond.IMPLICIT),
new Edge(0, 3, Bond.IMPLICIT),
new Edge(0, 4, Bond.IMPLICIT),
new Edge(0, 5, Bond.IMPLICIT),
new Edge(0, 6, Bond.IMPLICIT));
Topology t = Topology.create(0, vs, es, Configuration.OH1);
assertThat(t.configuration(), is(Configuration.OH1));
assertThat(t.atom(), is(0));
}

@Test(expected = IllegalArgumentException.class)
Expand Down
2 changes: 1 addition & 1 deletion exec/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<artifactId>beam</artifactId>
<groupId>uk.ac.ebi.beam</groupId>
<version>1.0</version>
<version>1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion func/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>beam</artifactId>
<groupId>uk.ac.ebi.beam</groupId>
<version>1.0</version>
<version>1.1-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<description>SMILES parsing and generation library for cheminformatics</description>
<url>http://www.github.com/johnmay/beam/</url>
<packaging>pom</packaging>
<version>1.0</version>
<version>1.1-SNAPSHOT</version>
<modules>
<module>core</module>
<module>func</module>
Expand Down

2 comments on commit 8c9c77a

@sp
Copy link

@sp sp commented on 8c9c77a Nov 28, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi there. It looks like you inadvertently tagged me in your commit message -- just letting you know.

@johnmay
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And two others it looks like. Thanks, not sure if there's a way I can untag? Was referencing the chemistry configuration classes form a file-format (SMILES). SP: Square Planar, TB: Trigonal Bipyramidal, OH: Octahedral
http://www.daylight.com/dayhtml/doc/theory/theory.smiles.html
http://opensmiles.org/opensmiles.html#_square_planar_centers

Please sign in to comment.