-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPluginLogic.java
More file actions
116 lines (97 loc) · 4.99 KB
/
PluginLogic.java
File metadata and controls
116 lines (97 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package com.chemaxon.designhub.plugin.exampleimpl;
import com.chemaxon.designhub.plugin.interfaces.RealtimePluginInterface;
import com.chemaxon.designhub.plugin.interfaces.ResultSet;
import com.chemaxon.designhub.plugin.settings.types.BooleanPluginSetting;
import com.chemaxon.designhub.plugin.settings.types.NumberPluginSetting;
import com.chemaxon.designhub.plugin.settings.types.StringPluginSetting;
import chemaxon.calculations.ElementalAnalyser;
import chemaxon.formats.MolImporter;
import chemaxon.struc.Molecule;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.util.HashMap;
import java.util.Map;
@Component
public class PluginLogic implements RealtimePluginInterface<PluginSettings> {
private static final Logger logger = LoggerFactory.getLogger(PluginLogic.class);
private final PluginSettings myDefaultSettings = new PluginSettings(
new BooleanPluginSetting("Enable report data", true),
new StringPluginSetting("Put some nice string here", ""),
new NumberPluginSetting("Custom atom count", 4));
public ResultSet getResultSet(String structure, String pinnedStructure, PluginSettings settings, Map<String, Object> context) {
logger.debug("We just received some data!");
try {
Molecule mol = MolImporter.importMol(structure);
ElementalAnalyser elementalAnalyser = new ElementalAnalyser();
elementalAnalyser.setMolecule(mol);
double exactMass = elementalAnalyser.exactMass();
double mass = elementalAnalyser.mass();
int massPrecision = elementalAnalyser.massPrecision();
int atomCount1 = elementalAnalyser.atomCount(8); // oxygen atom count
int atomCount2 = elementalAnalyser.atomCount(8, 0); // non-isotope oxygen count
int atomCount3 = elementalAnalyser.atomCount(8, 16); // oxygen isotope count with massno=16
String formula = elementalAnalyser.formula();
String isotopeFormula = elementalAnalyser.isotopeFormula();
String composition = elementalAnalyser.composition(2); // precision=2
String isotopeComposition = elementalAnalyser.isotopeComposition(2); // precision=2
// now use the results...
ClientData clientData = new ClientData();
clientData.setAtomCount1(atomCount1);
clientData.setAtomCount2(atomCount2);
clientData.setAtomCount3(atomCount3);
clientData.setFormula(formula);
clientData.setIsotopeFormula(isotopeFormula);
clientData.setComposition(composition);
clientData.setIsotopeComposition(isotopeComposition);
// using settings
int customAtomCountSetting = settings.getAtomCount().getValue().intValue();
clientData.setCustomAtomCount(elementalAnalyser.atomCount(customAtomCountSetting));
clientData.setSettingOfCustomAtomCount(customAtomCountSetting);
if (settings.getReportEnabled().getValue()) {
Map<String, Object> reportData = new HashMap<>();
reportData.put("Oxygen atom count", atomCount1);
reportData.put("Non-isotope oxygen count", atomCount2);
reportData.put("Some boolean data", true);
reportData.put("Some string data", "Report data!");
return ResultSet.of(clientData, reportData);
}
// Return null in the case this plugin should not provide any report data
return ResultSet.of(clientData, null);
} catch (Exception e) {
logger.error("There was an error processing this calculation structure: {}", structure);
logger.error(e.getMessage());
return ResultSet.EMPTY;
}
}
@Override
public PluginSettings getSettings() {
return myDefaultSettings;
}
@Override
public String getLabel() {
return "Example plugin label";
}
@Override
public String getName() {
return "example-java-plugin-name";
}
@Override
public String getTemplate() {
// For more details see docs: https://docs.chemaxon.com/display/docs/design-hub-developer-guide-real-time-plugin-templates.md
return "<div>\n" +
" <p>Oxygen atom count: {{client.atomCount1}}</p>\n" +
" <p>Non-isotope oxygen count: {{client.atomCount2}}</p>\n" +
" <p>Oxygen isotope count with massno=16: {{client.atomCount3}}</p>\n" +
" <p>Custom set ({{client.settingOfCustomAtomCount}}) atom count: {{client.customAtomCount}}</p>\n" +
" <p>Formula: {{client.formula}}</p>\n" +
" <p>Isotope formula: {{client.isotopeFormula}}</p>\n" +
" <p>Composition: {{client.composition}}</p>\n" +
" <p>Isotope composition: {{client.isotopeComposition}}</p>\n" +
"</div>";
}
@Override
public boolean hasReport() {
return true;
}
}