Skip to content

Commit

Permalink
Merge pull request #294 from ncats/fixSmartsRender
Browse files Browse the repository at this point in the history
fixing rendering of CV fragments
  • Loading branch information
ChemMitch authored Nov 1, 2023
2 parents 910c382 + 0385dab commit 3304908
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 13 deletions.
Binary file not shown.
2 changes: 1 addition & 1 deletion gsrs-module-substance-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
<dependency>
<groupId>gov.nih.ncats</groupId>
<artifactId>molwitch-cdk</artifactId>
<version>1.0.12-SNAPSHOT</version>
<version>1.0.14-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
4 changes: 2 additions & 2 deletions gsrs-module-substances-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
<dependency>
<groupId>gov.nih.ncats</groupId>
<artifactId>molwitch</artifactId>
<version>0.6.3-SNAPSHOT</version>
<version>0.6.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>gov.nih.ncats</groupId>
<artifactId>molwitch-cdk</artifactId>
<version>1.0.9</version>
<version>1.0.14</version>
</dependency>
<dependency>
<groupId>gov.nih.ncats</groupId>
Expand Down
4 changes: 2 additions & 2 deletions gsrs-module-substances-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<dependency>
<groupId>gov.nih.ncats</groupId>
<artifactId>molwitch-renderer</artifactId>
<version>1.0.13-SNAPSHOT</version>
<version>1.0.14-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>gov.nih.ncats</groupId>
Expand Down Expand Up @@ -214,7 +214,7 @@
<dependency>
<groupId>gov.nih.ncats</groupId>
<artifactId>molwitch</artifactId>
<version>0.6.3-SNAPSHOT</version>
<version>0.6.5-SNAPSHOT</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package gsrs.module.substance.controllers;

import com.fasterxml.jackson.databind.JsonNode;

import gov.nih.ncats.molwitch.Atom;
import gov.nih.ncats.molwitch.Chemical;
import gov.nih.ncats.molwitch.MolwitchException;
import gsrs.cache.GsrsCache;
Expand Down Expand Up @@ -296,7 +298,35 @@ private static Chemical parseAndComputeCoordsIfNeeded(String input) throws IOExc
Chemical c = Chemical.parse(input);
if(!c.getSource().get().getType().includesCoordinates()){
try {
// If it's an in-line format, there's an extra cleanup step
// we do to avoid an issue with parsing some query forms
// TODO: this is really a hack because molwitch-cdk considers any
// molecule with a * to be query-based, and turns lots of
// other atoms inside into query atoms. This makes some downstream
// renderer calculations not work well. The solution here is
// to actually parse * atoms as Helium atoms and give them a * alias.
// Since this is only used for rendering, it tends to be okay.
// If this were ever used for "real" calculations we'd need to do
// something more thorough.
String potentialCXSmarts = c.getSource().get().getData();

if(potentialCXSmarts.contains("*")) {
//this means there's a query atom
potentialCXSmarts = potentialCXSmarts.replace("[*]", "[He:17]");
potentialCXSmarts = potentialCXSmarts.replace("*", "[He:17]");
c=Chemical.parse(potentialCXSmarts);
c.atoms().filter(at->at.getAtomToAtomMap().isPresent() && at.getAtomToAtomMap().getAsInt()==17)
.filter(at->"He".equals(at.getSymbol()))
.forEach(at->{
Atom aa=at;
if(!aa.getAlias().isPresent()) {
aa.setAlias("*");
aa.setAtomToAtomMap(0);
}
});
}
c.generateCoordinates();

} catch (MolwitchException e) {
throw new IOException("error generating coordinates",e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1405,7 +1405,6 @@ public byte[] renderChemical (Structure struc, Chemical chem, String format,
rendererOptions.changeSettings(newDisplay);
}


//TODO: This would be nice to get back eventually, for standardization:
//chem.reduceMultiples();

Expand Down Expand Up @@ -1475,6 +1474,18 @@ public byte[] renderChemical (Structure struc, Chemical chem, String format,
if (!fullRendererOptions.isShowShadow()) {
renderer.setShadowVisible(false);
}
//
// if (fullRendererOptions.isAddBorder()) {
// renderer.setBorderVisible(true);
// if(fullRendererOptions.getColorBorder()!=null) {
// renderer.setBorderColorARGB(fullRendererOptions.getColorBorder());
// }
// }
//
// if (fullRendererOptions.getColorBg()!=null) {
// renderer.setBorderColorARGB(fullRendererOptions.getColorBg());
// }


ByteArrayOutputStream bos = new ByteArrayOutputStream();

Expand Down Expand Up @@ -1520,6 +1531,7 @@ private static void preProcessChemical(Chemical c, RendererOptions renderOption
boolean hasRgroups=hasRGroups(c);
int rgroupColor=1;


if(hasRgroups){
if(fuse){
compColor=colorChemicalComponents(c);
Expand Down Expand Up @@ -1604,6 +1616,8 @@ public static boolean hasRGroups(Chemical c){
// }
// }
boolean r=false;


for(Atom ca:c.getAtoms()){
if(ca.getRGroupIndex().isPresent()){
r= true;
Expand All @@ -1614,6 +1628,9 @@ public static boolean hasRGroups(Chemical c){
if(alias.startsWith("_R")){
ca.setRGroup(Integer.parseInt(alias.replace("_R", "")));
r= true;
}else if(alias.startsWith("R")){
ca.setRGroup(Integer.parseInt(alias.replace("R", "")));
r= true;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,14 @@ public String canonicalSmiles(Structure s, String mol) {
@Override
public Chemical standardize(Chemical orig, Supplier<String> molSupplier, Consumer<Value> valueConsumer) throws IOException {

// if(true){
// return orig;
// }
// This is currently a no-op for now. The inchi standardizer appears to have some
// bugs that are not well understood.
// In general it's not actually needed, since we tend to use the inchi hasher which will already do a pre-standardization step.
//

if(true){
return orig;
}
if(orig.getAtomCount() > maxNumberOfAtoms || orig.hasPseudoAtoms()){
return orig;
}
Expand Down
2 changes: 1 addition & 1 deletion gsrs-module-substances-dto/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>gov.nih.ncats</groupId>
<artifactId>molwitch</artifactId>
<version>0.6.3-SNAPSHOT</version>
<version>0.6.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>gov.nih.ncats</groupId>
Expand Down
2 changes: 1 addition & 1 deletion gsrs-module-substances-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<dependency>
<groupId>gov.nih.ncats</groupId>
<artifactId>molwitch</artifactId>
<version>0.6.3-SNAPSHOT</version>
<version>0.6.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>gov.nih.ncats</groupId>
Expand Down
2 changes: 1 addition & 1 deletion installExtraJars.cmd
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
mvnw.cmd install:install-file -Dfile=extraJars/applications-api-3.1-SNAPSHOT.jar
mvnw.cmd install:install-file -Dfile=extraJars/products-api-3.1-SNAPSHOT.jar
mvnw.cmd install:install-file -Dfile=extraJars/clinical-trials-api-3.1-SNAPSHOT.jar
mvnw.cmd install:install-file -Dfile=extraJars/molwitch-renderer-1.0.13-SNAPSHOT.jar
mvnw.cmd install:install-file -Dfile=extraJars/molwitch-renderer-1.0.14-SNAPSHOT.jar

2 changes: 1 addition & 1 deletion installExtraJars.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
./mvnw install:install-file -Dfile=extraJars/applications-api-3.1-SNAPSHOT.jar
./mvnw install:install-file -Dfile=extraJars/products-api-3.1-SNAPSHOT.jar
./mvnw install:install-file -Dfile=extraJars/clinical-trials-api-3.1-SNAPSHOT.jar
./mvnw install:install-file -Dfile=extraJars/molwitch-renderer-1.0.13-SNAPSHOT.jar
./mvnw install:install-file -Dfile=extraJars/molwitch-renderer-1.0.14-SNAPSHOT.jar

0 comments on commit 3304908

Please sign in to comment.