Skip to content

Commit

Permalink
allow render configs to work
Browse files Browse the repository at this point in the history
  • Loading branch information
tylerperyea committed Nov 3, 2023
1 parent 4a1a500 commit 3e3b558
Show file tree
Hide file tree
Showing 4 changed files with 98 additions and 8 deletions.
2 changes: 1 addition & 1 deletion 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.14-SNAPSHOT</version>
<version>1.0.15-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>gov.nih.ncats</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import gov.nih.ncats.molvec.internal.util.CachedSupplier;
import gov.nih.ncats.molwitch.renderer.RendererOptions;
import gsrs.module.substance.RendererOptionsConfig.FullRenderOptions;
import gsrs.module.substance.RendererOptionsConfig.FullRenderOptions.FullRenderOptionsBuilder;
import lombok.AccessLevel;
import lombok.Data;
import lombok.Getter;
Expand All @@ -39,7 +40,7 @@ public class GSRSRendererConfiguration {
if(list!=null) {
for(Map m:list.values()) {
String name = m.getOrDefault("name", "").toString();
FullRenderOptions base = FullRenderOptions.builder().build();
FullRenderOptionsBuilder baseBuilder = FullRenderOptions.builder();
if(name==null || name.length()==0) {
log.error("Render settings must have names, gsrs.renderers.list[%i] does not have a name. That render config will be skipped.", i);
continue;
Expand All @@ -53,20 +54,40 @@ public class GSRSRendererConfiguration {

if(renderer.get("preset")!=null) {
String preset=renderer.get("preset").toString();
base=renderMap.getOrDefault(preset, getFullRendererOptionsByName(preset).orElse(null));
if(base==null) {

FullRenderOptions opt=Optional.ofNullable(renderMap.get(preset)).orElseGet(()->getDefaultRendererOptionsByName(preset).orElse(null));


if(opt==null) {
log.warn("Render settings preset '%s' not found as a valid preset. The default render config will be used instead.", preset);
base = FullRenderOptions.builder().build();
opt = FullRenderOptions.builder().build();
}
baseBuilder=opt.toBuilder();
}
Map<String,Object> options = (Map<String,Object>) renderer.get("options");
if(options!=null) {

RendererOptions ropts= baseBuilder.build().getOptions();
ropts=ropts.changeSettings(options);
baseBuilder=baseBuilder.options(ropts);
}

FullRenderOptionsBuilder baseBuilderFinal = baseBuilder;

Optional.ofNullable(renderer.get("add-shadow")).ifPresent(ss->{
baseBuilderFinal.showShadow("true".equalsIgnoreCase(ss.toString()));
});
Optional.ofNullable(renderer.get("add-border")).ifPresent(ss->{
baseBuilderFinal.addBorder("true".equalsIgnoreCase(ss.toString()));
});
Optional.ofNullable(renderer.get("color-bg")).ifPresent(ss->{
baseBuilderFinal.colorBg(ss.toString());
});
Optional.ofNullable(renderer.get("color-border")).ifPresent(ss->{
baseBuilderFinal.colorBorder(ss.toString());
});


renderMap.put(name,base);
renderMap.put(name,baseBuilderFinal.build());
i++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.databind.ObjectMapper;

import gov.nih.ncats.common.util.CachedSupplier;
import gov.nih.ncats.molwitch.renderer.ARGBColor;
import gov.nih.ncats.molwitch.renderer.ColorPalette;
import gov.nih.ncats.molwitch.renderer.RendererOptions;
import lombok.Builder;
import lombok.Data;
Expand Down Expand Up @@ -51,7 +56,8 @@ public static class FullRenderOptions{
public FullRenderOptions copy() {
return toBuilder()
.build();
}
}

public FullRenderOptionsBuilder toBuilder(){
return FullRenderOptions.builder()
.options(options.copy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -753,3 +753,66 @@ gsrs.processing-strategy = {
{"regex": "E4562650", "userRoles": ["SuperUpdate", "SuperDataEntry"], "newMessageType": "WARNING"}
]
}










# This shows how special render settings can be applied
# at a pretty deep explicit level. This is ported over largely from how
# it was done in GSRS 2.8
#
#
# 1. Supports embedded JSON options definitions for the structure renderer
# 2. Supports naming styles for use
# 3. Supports using previously named styles and making variations of them
#
gsrs.renderers.list=[
{
"name" : "CLEAN",
"renderer" :{
"preset": "USP", //Note this part
"options" : {
"PROP_KEY_DRAW_GREYSCALE" : false,
"ATOM_LABEL_FONT_FRACTION" : 0.47918,
"ATOM_LABEL_BOND_GAP_FRACTION" :1.02,
"BOND_STROKE_WIDTH_FRACTION" : 0.032,
"BOND_DOUBLE_GAP_FRACTION": 0.1995,
"BOND_STEREO_WEDGE_ANGLE" : 0.13659,
"BOND_STEREO_DASH_NUMBER" :8,
"SUBSCRIPT_Y_DISPLACEMENT_FRACTION" : 0.17,
"DRAW_WEDGE_AS_POINT" : false,
"DRAW_STEREO_WEDGE_JOIN" : true,
"DRAW_STEREO_LAST_DASH_ON_NON_SYMBOLS" : false,
"colorPalette" : {
"atomColors" : {
"C" : "FFFF0000" // red carbons (ugly)
}
}
},
"add-shadow" : true,
"add-border" : false
}
},
{
"name" : "CLEAN1",
"renderer" :{
"preset": "CLEAN", //Note this part
"options" : {
"BOND_STROKE_WIDTH_FRACTION" : 0.64
},
"add-shadow" : false,
"add-border" : false
}
}
]

# Here, you can specify the main renderer style to use, which can be one of the default supported cases
# or can be one of the specified cases in the list above.

#gsrs.renderers.selected="CLEAN1"

0 comments on commit 3e3b558

Please sign in to comment.