Skip to content

Commit 7be5126

Browse files
committed
better parser for solver-generated observables
1 parent de36f6f commit 7be5126

File tree

2 files changed

+57
-26
lines changed

2 files changed

+57
-26
lines changed

vcell-client/src/main/java/cbit/vcell/client/data/SimulationWorkspaceModelInfo.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -379,17 +379,17 @@ public void populateDataSymbolMetadata(ColumnDescription[] cdArray) {
379379
String columnName = cd.getName();
380380
ModelCategoryType filterCategory = null; // parse name to find the filter category
381381
SsldUtils.LangevinResult lr = SsldUtils.LangevinResult.fromString(columnName);
382-
if(!(lr.qualifier.equals("FREE") || lr.qualifier.equals("BOUND") || lr.qualifier.equals("TOTAL"))) {
383-
System.out.println("Ignoring LangevinResult token: " + columnName);
382+
if(lr.qualifier.equals(SsldUtils.Qualifier.NONE)) {
383+
System.out.println("Ignoring LangevinResult token: " + columnName + ", qualifier missing");
384384
continue;
385385
}
386386
if(!lr.molecule.isEmpty() && lr.site.isEmpty() && lr.state.isEmpty()) {
387387
filterCategory = BioModelCategoryType.Molecules;
388-
} else if(lr.qualifier.equals("FREE") && !lr.molecule.isEmpty() && !lr.site.isEmpty() && !lr.state.isEmpty()) {
388+
} else if(lr.qualifier.equals(SsldUtils.Qualifier.FREE) && !lr.molecule.isEmpty() && !lr.site.isEmpty() && !lr.state.isEmpty()) {
389389
filterCategory = BioModelCategoryType.FreeSites;
390-
} else if(lr.qualifier.equals("BOUND") && !lr.molecule.isEmpty() && !lr.site.isEmpty() && !lr.state.isEmpty()) {
390+
} else if(lr.qualifier.equals(SsldUtils.Qualifier.BOUND) && !lr.molecule.isEmpty() && !lr.site.isEmpty() && !lr.state.isEmpty()) {
391391
filterCategory = BioModelCategoryType.BoundSites;
392-
} else if(lr.qualifier.equals("TOTAL") && !lr.molecule.isEmpty() && !lr.site.isEmpty() && !lr.state.isEmpty()) {
392+
} else if(lr.qualifier.equals(SsldUtils.Qualifier.TOTAL) && !lr.molecule.isEmpty() && !lr.site.isEmpty() && !lr.state.isEmpty()) {
393393
filterCategory = BioModelCategoryType.TotalSites;
394394
}
395395
VCUnitDefinition unit = null;

vcell-core/src/main/java/org/vcell/model/ssld/SsldUtils.java

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,43 +24,74 @@
2424

2525
public class SsldUtils {
2626

27+
public enum Qualifier {
28+
FREE, BOUND, TOTAL, NONE;
29+
public static Qualifier fromPrefix(String s) {
30+
for (Qualifier q : values()) {
31+
if (q != NONE && q.name().equals(s)) {
32+
return q;
33+
}
34+
}
35+
return NONE;
36+
}
37+
}
38+
2739
// result entry from langevin output
2840
public static class LangevinResult {
29-
public final String qualifier;
41+
public final Qualifier qualifier;
3042
public final String molecule;
3143
public final String site;
3244
public final String state;
3345

3446
public static LangevinResult fromString(String str) {
35-
if(str == null || str.length() == 0) {
47+
if (str == null || str.isEmpty()) {
3648
throw new RuntimeException("Langevin generated molecules name must contain some text");
3749
}
38-
String qualifier = "";
39-
String molecule = "";
50+
51+
// Step 1: split only on DOUBLE underscore
52+
String[] parts = str.split("__");
53+
54+
String first = parts[0];
55+
56+
// Step 2: find first underscore
57+
int idx = first.indexOf('_');
58+
59+
Qualifier qualifier = Qualifier.NONE;
60+
String molecule;
61+
62+
if (idx > 0) {
63+
String prefix = first.substring(0, idx);
64+
qualifier = Qualifier.fromPrefix(prefix);
65+
66+
if (qualifier != Qualifier.NONE) {
67+
// Valid qualifier found
68+
molecule = first.substring(idx + 1);
69+
} else {
70+
// Not a valid qualifier → whole thing is molecule
71+
molecule = first;
72+
}
73+
} else {
74+
// No underscore at all → no qualifier
75+
molecule = first;
76+
}
77+
4078
String site = "";
4179
String state = "";
4280

43-
String[] tokens = str.split("_{1,2}");
44-
if(tokens.length <1 || tokens.length > 4) {
45-
throw new RuntimeException("Langevin generated molecules name must have between one and 4 tokens");
81+
if (parts.length >= 2) {
82+
site = parts[1];
4683
}
47-
for (int i=0; i<tokens.length; i++) {
48-
String token = tokens[i];
49-
if(i == 0) {
50-
qualifier = token;
51-
} else if(i == 1) {
52-
molecule = token;
53-
} else if(i == 2) {
54-
site = token;
55-
} else if(i == 3) {
56-
state = token;
57-
}
84+
if (parts.length >= 3) {
85+
state = parts[2];
5886
}
59-
LangevinResult lr = new LangevinResult(qualifier, molecule, site, state);
60-
return lr;
87+
if (parts.length > 3) {
88+
throw new RuntimeException("Too many '__' sections in: " + str);
89+
}
90+
91+
return new LangevinResult(qualifier, molecule, site, state);
6192
}
6293

63-
public LangevinResult(String qualifier, String molecule, String site, String state) {
94+
public LangevinResult(Qualifier qualifier, String molecule, String site, String state) {
6495
this.qualifier = qualifier;
6596
this.molecule = molecule;
6697
this.site = site;

0 commit comments

Comments
 (0)