Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix stereo bug #19

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
31 changes: 29 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>gov.nih.ncats</groupId>
<artifactId>molwitch-cdk</artifactId>
<version>1.0.14</version>
<version>1.0.15-SNAPSHOT</version>
<name>molwitch-cdk</name>

<url>https://github.com/ncats/molwitch-cdk/</url>
Expand All @@ -18,6 +18,7 @@

<properties>
<cdk.version>2.9</cdk.version>
<centres.version>1.2.1</centres.version>
</properties>
<repositories>
<repository>
Expand All @@ -30,6 +31,16 @@
<enabled>true</enabled>
</snapshots>
</repository>
<repository>
<id>oss.sonatype.org</id>
<url>https://repo1.maven.org/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>

<developers>
Expand Down Expand Up @@ -73,7 +84,7 @@
<dependency>
<groupId>gov.nih.ncats</groupId>
<artifactId>molwitch</artifactId>
<version>0.6.5</version>
<version>0.6.6-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
Expand Down Expand Up @@ -112,6 +123,22 @@
<artifactId>cdk-jniinchi-support</artifactId>
<version>${cdk.version}</version>
</dependency>


<dependency>
<groupId>com.simolecule.centres</groupId>
<artifactId>centres-core</artifactId>
<version>${centres.version}</version>
</dependency>

<dependency>
<groupId>com.simolecule.centres</groupId>
<artifactId>centres-cdk</artifactId>
<version>${centres.version}</version>
</dependency>



<!-- <dependency>-->
<!-- <groupId>org.openscience.cdk</groupId>-->
<!-- <artifactId>cdk-valencycheck</artifactId>-->
Expand Down
61 changes: 56 additions & 5 deletions src/main/java/gov/nih/ncats/molwitch/cdk/CdkAtom.java
Original file line number Diff line number Diff line change
Expand Up @@ -306,16 +306,31 @@ public void setAtomCoordinates(AtomCoordinates atomCoordinates) {
public Chirality getChirality() {
if(!parent.cahnIngoldPrelogSupplier.hasRun()) {
//forces running CIP rules

parent.getTetrahedrals();
}
String value = atom.getProperty(CDKConstants.CIP_DESCRIPTOR);
String value= Optional.ofNullable(atom.getProperty(CDKConstants.CIP_DESCRIPTOR))
.map(t->t.toString())
.orElse(null);

if("R".equals(value)) {
// if(dd!=nu)
// String value = atom.getProperty(CDKConstants.CIP_DESCRIPTOR);
//
if("R".equals(value) || "M".equals(value)) {
return Chirality.R;
}
if("S".equals(value)) {
if("r".equals(value)) {
return Chirality.r;
}

if("S".equals(value) || "P".equals(value)) {
return Chirality.S;
}

if("s".equals(value)) {
return Chirality.s;
}

if("EITHER".equals(value)) {
return Chirality.Parity_Either;
}
Expand All @@ -327,8 +342,10 @@ public Chirality getChirality() {
public void setChirality(Chirality chirality) {
Chirality chir=getChirality();
if(chir==chirality)return;
if((chirality==Chirality.R && chir==Chirality.S) ||
(chirality==Chirality.S && chir==Chirality.R)

//simple inversion
if(((chirality==Chirality.R || chirality==Chirality.r) && (chir==Chirality.S||chir==Chirality.s)) ||
((chirality==Chirality.S || chirality==Chirality.s) && (chir==Chirality.R||chir==Chirality.r))
) {
this.getBonds().stream()
.filter(b->b.getBondType().equals(BondType.SINGLE))
Expand All @@ -345,6 +362,8 @@ public void setChirality(Chirality chirality) {
atom.setProperty(CDKConstants.CIP_DESCRIPTOR,chirality.toString());
// atom.setStereoParity((atom.getStereoParity()+1)%2);
// parent.getContainer().setStereoElements(new ArrayList<>());

//simple removal
}else if(chirality.equals(Chirality.Parity_Either)) {
this.getBonds().stream()
.filter(b->b.getBondType().equals(BondType.SINGLE))
Expand All @@ -359,7 +378,39 @@ public void setChirality(Chirality chirality) {
});

atom.setProperty(CDKConstants.CIP_DESCRIPTOR,"EITHER");
}else if(chirality.isDefined() && (chir.isEither() || chir == Chirality.Non_Chiral)) {

Optional<? extends Bond> sBond = this.getBonds().stream()
.filter(b->b.getBondType().equals(BondType.SINGLE))
.filter(b->b.getStereo().equals(Stereo.NONE))
.findFirst();


sBond.ifPresent(b->{
if(b.getAtom1().getAtomIndexInParent()==this.getAtomIndexInParent()){
b.setStereo(Stereo.UP);
}else {
b.setStereo(Stereo.UP_INVERTED);
}
});


parent.cahnIngoldPrelogSupplier.resetCache();
Chirality co=this.getChirality();
if((co.isRForm() && chirality.isRForm()) ||
(co.isSForm() && chirality.isSForm())
) {
//do nothing
}else if((co.isSForm() && chirality.isRForm()) ||
(co.isRForm() && chirality.isSForm())
) {
setChirality(chirality);
}else {
//could not set
}

}

// parent.cahnIngoldPrelogSupplier.resetCache();
}

Expand Down
6 changes: 2 additions & 4 deletions src/main/java/gov/nih/ncats/molwitch/cdk/CdkBond.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@
package gov.nih.ncats.molwitch.cdk;


import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

import org.openscience.cdk.BondRef;
import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IBond.Order;
import org.openscience.cdk.interfaces.IStereoElement;
import org.openscience.cdk.isomorphism.matchers.IQueryBond;

import gov.nih.ncats.common.sneak.Sneak;
Expand Down Expand Up @@ -224,7 +222,7 @@ public DoubleBondStereo getDoubleBondStereo() {
return null;
}
parent.cahnIngoldPrelogSupplier.get();
String value = bond.getProperty(CDKConstants.CIP_DESCRIPTOR);
String value = Optional.ofNullable(bond.getProperty(CDKConstants.CIP_DESCRIPTOR)).map(bt->bt.toString()).orElse(null);
if("Z".equals(value)) {
return DoubleBondStereo.Z_CIS;
}
Expand Down
Loading