Skip to content

Commit 17f9cf3

Browse files
authored
Merge pull request #1650 from virtualcell/libvcell_new
Refactors VCell Object Cloning and Enhances Libvcell Data Access
2 parents 6a44548 + 204cea5 commit 17f9cf3

41 files changed

Lines changed: 471 additions & 557 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

vcell-client/src/main/java/cbit/vcell/client/ClientRequestManager.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ public XmlTreeDiff compareWithSaved(VCDocument document) {
630630
public XmlTreeDiff compareApplications(BioModel bioModel, String appName1, String appName2) throws Exception {
631631

632632
// clone BioModel as bioModel1 and remove all but appName1
633-
BioModel bioModel1 = (BioModel) BeanUtils.cloneSerializable(bioModel);
633+
BioModel bioModel1 = XmlHelper.cloneBioModel(bioModel);
634634
bioModel1.refreshDependencies();
635635
SimulationContext[] allSimContexts1 = bioModel1.getSimulationContexts();
636636
for (SimulationContext sc : allSimContexts1) {
@@ -640,7 +640,7 @@ public XmlTreeDiff compareApplications(BioModel bioModel, String appName1, Strin
640640
}
641641

642642
// clone BioModel as bioModel2 and remove all but appName2
643-
BioModel bioModel2 = (BioModel) BeanUtils.cloneSerializable(bioModel);
643+
BioModel bioModel2 = XmlHelper.cloneBioModel(bioModel);
644644
bioModel2.refreshDependencies();
645645
SimulationContext[] allSimContexts2 = bioModel2.getSimulationContexts();
646646
for (SimulationContext sc : allSimContexts2) {

vcell-client/src/main/java/cbit/vcell/client/task/RunSims.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.Vector;
1515

1616
import cbit.vcell.solver.*;
17+
import cbit.vcell.xml.XmlHelper;
1718
import org.vcell.util.*;
1819
import org.vcell.util.document.VCDocument;
1920
import org.vcell.util.gui.DialogUtils;
@@ -197,7 +198,7 @@ public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception
197198
int defaultTotalVolumeElements = mathGeometry.getGeometrySurfaceDescription().getVolumeSampleSize().getXYZ();
198199
int newTotalVolumeElements = meshSpecification.getSamplingSize().getXYZ();
199200
if (defaultTotalVolumeElements > newTotalVolumeElements) { // coarser
200-
Geometry resampledGeometry = (Geometry) BeanUtils.cloneSerializable(mathGeometry);
201+
Geometry resampledGeometry = XmlHelper.cloneGeometry(mathGeometry);
201202
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
202203
geoSurfaceDesc.setVolumeSampleSize(newSize);
203204
geoSurfaceDesc.updateAll();

vcell-client/src/main/java/cbit/vcell/geometry/gui/SurfaceViewer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ private cbit.vcell.geometry.surface.SurfaceCollection getCentroidSurface(cbit.vc
550550
cbit.vcell.geometry.surface.OrigSurface quadSurface = (cbit.vcell.geometry.surface.OrigSurface)quadSurfaceCollection.getSurfaces(0);
551551
cbit.vcell.geometry.surface.OrigSurface quadSurfaceCopy = null;
552552
try {
553-
quadSurfaceCopy = (cbit.vcell.geometry.surface.OrigSurface)org.vcell.util.BeanUtils.cloneSerializable(quadSurface);
553+
quadSurfaceCopy = quadSurface.deepClone();
554554
}catch (Throwable e){
555555
e.printStackTrace(System.out);
556556
throw new RuntimeException(e.getMessage());

vcell-client/src/main/java/cbit/vcell/graph/gui/BioCartoonTool.java

Lines changed: 19 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,78 +9,38 @@
99
*/
1010

1111
package cbit.vcell.graph.gui;
12-
import java.awt.Component;
13-
import java.awt.Dimension;
14-
import java.awt.Window;
15-
import java.beans.PropertyVetoException;
16-
import java.util.ArrayList;
17-
import java.util.HashMap;
18-
import java.util.HashSet;
19-
import java.util.Hashtable;
20-
import java.util.IdentityHashMap;
21-
import java.util.Iterator;
22-
import java.util.LinkedHashMap;
23-
import java.util.LinkedHashSet;
24-
import java.util.List;
25-
import java.util.Map;
26-
import java.util.Map.Entry;
27-
import java.util.Set;
28-
import java.util.Vector;
29-
30-
import javax.swing.JComboBox;
31-
import javax.swing.JOptionPane;
32-
import javax.swing.JTextField;
33-
34-
import org.vcell.model.rbm.MolecularType;
35-
import org.vcell.model.rbm.RbmNetworkGenerator.CompartmentMode;
36-
import org.vcell.model.rbm.RbmUtils;
37-
import org.vcell.model.rbm.SpeciesPattern;
38-
import org.vcell.util.BeanUtils;
39-
import org.vcell.util.CommentStringTokenizer;
40-
import org.vcell.util.Compare;
41-
import org.vcell.util.Issue;
42-
import org.vcell.util.Issue.IssueCategory;
43-
import org.vcell.util.IssueContext;
44-
import org.vcell.util.IssueContext.ContextType;
45-
import org.vcell.util.document.KeyValue;
46-
import org.vcell.util.TokenMangler;
47-
import org.vcell.util.UserCancelException;
48-
import org.vcell.util.gui.DialogUtils;
4912

5013
import cbit.gui.graph.gui.GraphPane;
5114
import cbit.vcell.client.task.AsynchClientTask;
5215
import cbit.vcell.client.task.ClientTaskDispatcher;
5316
import cbit.vcell.clientdb.DocumentManager;
54-
import cbit.vcell.model.BioModelEntityObject;
55-
import cbit.vcell.model.Catalyst;
56-
import cbit.vcell.model.Feature;
57-
import cbit.vcell.model.FluxReaction;
58-
import cbit.vcell.model.Kinetics;
17+
import cbit.vcell.model.*;
5918
import cbit.vcell.model.Kinetics.KineticsParameter;
6019
import cbit.vcell.model.Kinetics.KineticsProxyParameter;
61-
import cbit.vcell.model.KineticsDescription;
62-
import cbit.vcell.model.Membrane;
6320
import cbit.vcell.model.Membrane.MembraneVoltage;
64-
import cbit.vcell.model.Model;
6521
import cbit.vcell.model.Model.ModelParameter;
6622
import cbit.vcell.model.Model.RbmModelContainer;
6723
import cbit.vcell.model.Model.StructureTopology;
68-
import cbit.vcell.model.ModelException;
69-
import cbit.vcell.model.Product;
70-
import cbit.vcell.model.Reactant;
71-
import cbit.vcell.model.ReactionDescription;
72-
import cbit.vcell.model.ReactionParticipant;
73-
import cbit.vcell.model.ReactionRule;
74-
import cbit.vcell.model.ReactionSpeciesCopy;
75-
import cbit.vcell.model.ReactionStep;
76-
import cbit.vcell.model.SimpleReaction;
77-
import cbit.vcell.model.Species;
78-
import cbit.vcell.model.SpeciesContext;
79-
import cbit.vcell.model.Structure;
8024
import cbit.vcell.model.Structure.StructureSize;
8125
import cbit.vcell.parser.Expression;
8226
import cbit.vcell.parser.ExpressionBindingException;
8327
import cbit.vcell.parser.SymbolTableEntry;
28+
import cbit.vcell.xml.XmlHelper;
29+
import org.vcell.model.rbm.MolecularType;
30+
import org.vcell.model.rbm.RbmNetworkGenerator.CompartmentMode;
31+
import org.vcell.model.rbm.RbmUtils;
32+
import org.vcell.model.rbm.SpeciesPattern;
33+
import org.vcell.util.*;
34+
import org.vcell.util.Issue.IssueCategory;
35+
import org.vcell.util.IssueContext.ContextType;
36+
import org.vcell.util.gui.DialogUtils;
37+
38+
import javax.swing.*;
39+
import java.awt.*;
40+
import java.beans.PropertyVetoException;
41+
import java.util.*;
42+
import java.util.List;
43+
import java.util.Map.Entry;
8444

8545
public abstract class BioCartoonTool extends cbit.gui.graph.gui.CartoonTool {
8646
private DocumentManager documentManager = null;
@@ -338,7 +298,7 @@ public static final void pasteReactionsAndRules(Component requester, ReactionSpe
338298
AsynchClientTask issueTask = new AsynchClientTask("Checking Issues...",AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
339299
@Override
340300
public void run(Hashtable<String, Object> hashTable) throws Exception {
341-
Model clonedModel = (Model)org.vcell.util.BeanUtils.cloneSerializable(pasteModel);
301+
Model clonedModel = XmlHelper.cloneModel(pasteModel);
342302
clonedModel.refreshDependencies();
343303
// Model clonedModel = pasteModel;
344304
IssueContext issueContext = new IssueContext(ContextType.Model, clonedModel, null);
@@ -549,7 +509,7 @@ public void run(Hashtable<String, Object> hashTable) throws Exception {
549509
public void run(Hashtable<String, Object> hashTable) throws Exception {
550510
ReactionStep[] reactionStepsArrOrig = new ReactionStep[] {(ReactionStep)hashTable.get("fromRXStep")};
551511
UserResolvedRxElements userResolvedRxElements = (UserResolvedRxElements)hashTable.get("userResolvedRxElements");
552-
Model clonedModel = (Model)org.vcell.util.BeanUtils.cloneSerializable(pasteToModel);
512+
Model clonedModel = XmlHelper.cloneModel(pasteToModel);
553513
clonedModel.refreshDependencies();
554514
IssueContext issueContext = new IssueContext(ContextType.Model, clonedModel, null);
555515
HashMap<String,HashMap<ReactionParticipant,Structure>> userResolved_rxPartMapStruct = null;

vcell-core/src/main/java/cbit/vcell/biomodel/BioModel.java

Lines changed: 19 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,24 @@
1010

1111
package cbit.vcell.biomodel;
1212

13-
import java.beans.PropertyChangeListener;
14-
import java.beans.PropertyChangeSupport;
15-
import java.beans.PropertyVetoException;
16-
import java.beans.VetoableChangeListener;
17-
import java.beans.VetoableChangeSupport;
18-
import java.util.*;
19-
import java.util.function.Consumer;
20-
import java.util.stream.Collectors;
21-
13+
import cbit.image.ImageException;
2214
import cbit.image.VCImage;
15+
import cbit.vcell.biomodel.meta.IdentifiableProvider;
16+
import cbit.vcell.biomodel.meta.VCID;
17+
import cbit.vcell.biomodel.meta.VCMetaData;
18+
import cbit.vcell.geometry.*;
19+
import cbit.vcell.geometry.surface.GeometrySurfaceDescription;
2320
import cbit.vcell.mapping.*;
2421
import cbit.vcell.mapping.SimulationContext.Application;
22+
import cbit.vcell.math.MathDescription;
2523
import cbit.vcell.model.*;
24+
import cbit.vcell.model.Model.RbmModelContainer;
25+
import cbit.vcell.model.Structure.SpringStructureEnum;
26+
import cbit.vcell.parser.ExpressionException;
27+
import cbit.vcell.parser.NameScope;
28+
import cbit.vcell.parser.SymbolTableEntry;
29+
import cbit.vcell.solver.Simulation;
30+
import cbit.vcell.xml.XmlHelper;
2631
import org.apache.logging.log4j.LogManager;
2732
import org.apache.logging.log4j.Logger;
2833
import org.vcell.model.rbm.MolecularType;
@@ -38,24 +43,10 @@
3843
import org.vcell.util.document.*;
3944
import org.vcell.util.document.BioModelChildSummary.MathType;
4045

41-
import cbit.image.ImageException;
42-
import cbit.vcell.biomodel.meta.IdentifiableProvider;
43-
import cbit.vcell.biomodel.meta.VCID;
44-
import cbit.vcell.biomodel.meta.VCMetaData;
45-
import cbit.vcell.geometry.AnalyticSubVolume;
46-
import cbit.vcell.geometry.Geometry;
47-
import cbit.vcell.geometry.GeometryException;
48-
import cbit.vcell.geometry.GeometrySpec;
49-
import cbit.vcell.geometry.SubVolume;
50-
import cbit.vcell.geometry.SurfaceClass;
51-
import cbit.vcell.geometry.surface.GeometrySurfaceDescription;
52-
import cbit.vcell.math.MathDescription;
53-
import cbit.vcell.model.Model.RbmModelContainer;
54-
import cbit.vcell.model.Structure.SpringStructureEnum;
55-
import cbit.vcell.parser.ExpressionException;
56-
import cbit.vcell.parser.NameScope;
57-
import cbit.vcell.parser.SymbolTableEntry;
58-
import cbit.vcell.solver.Simulation;
46+
import java.beans.*;
47+
import java.util.*;
48+
import java.util.function.Consumer;
49+
import java.util.stream.Collectors;
5950

6051
/**
6152
* Insert the type's description here.
@@ -114,7 +105,7 @@ public void transformLumpedToDistributed(){
114105
Kinetics origKinetics = reactionStep.getKinetics();
115106
// clone it for backup purposes
116107
origKinetics.setReactionStep(null);
117-
Kinetics clonedKinetics = (Kinetics) BeanUtils.cloneSerializable(origKinetics);
108+
Kinetics clonedKinetics = XmlHelper.cloneReactionStep(reactionStep).getKinetics();
118109
origKinetics.setReactionStep(reactionStep);
119110
try {
120111
DistributedKinetics.toDistributedKinetics((LumpedKinetics) origKinetics, false);

vcell-core/src/main/java/cbit/vcell/bionetgen/BNGMolecule.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,15 @@ public void setComponentsStates(){
117117
public String toString(){
118118
return getName();
119119
}
120+
121+
public BNGMolecule deepClone() {
122+
BNGMolecule bngMoleculeClone = new BNGMolecule(getName());
123+
if (molComponents != null) {
124+
bngMoleculeClone.molComponents = new BNGSpeciesComponent[molComponents.length];
125+
for (int i = 0; i < molComponents.length; i++) {
126+
bngMoleculeClone.molComponents[i] = molComponents[i].deepClone();
127+
}
128+
}
129+
return bngMoleculeClone;
130+
}
120131
}

vcell-core/src/main/java/cbit/vcell/bionetgen/BNGOutputSpec.java

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,51 @@ public BNGOutputSpec(BNGParameter[] argParams, BNGMolecule[] argMols, BNGSpecies
4949
}
5050
}
5151

52+
public BNGOutputSpec deepClone() {
53+
BNGParameter[] bngParamsClone = null;
54+
if (bngParams != null) {
55+
bngParamsClone = new BNGParameter[bngParams.length];
56+
for (int i = 0; i < bngParams.length; i++) {
57+
bngParamsClone[i] = bngParams[i].deepClone();
58+
}
59+
}
60+
BNGMolecule[] bngMoleculeTypesClone = null;
61+
if (bngMoleculeTypes != null){
62+
bngMoleculeTypesClone = new BNGMolecule[bngMoleculeTypes.length];
63+
for (int i = 0; i < bngMoleculeTypes.length; i++) {
64+
bngMoleculeTypesClone[i] = bngMoleculeTypes[i].deepClone();
65+
}
66+
}
67+
BNGSpecies[] bngSpeciesClone = null;
68+
if (bngSpecies != null){
69+
bngSpeciesClone = new BNGSpecies[bngSpecies.length];
70+
for (int i = 0; i < bngSpecies.length; i++) {
71+
bngSpeciesClone[i] = bngSpecies[i].deepClone();
72+
}
73+
}
74+
BNGReactionRule[] bngReactionRulesClone = null;
75+
if (bngReactionRules != null){
76+
bngReactionRulesClone = new BNGReactionRule[bngReactionRules.length];
77+
for (int i = 0; i < bngReactionRules.length; i++) {
78+
bngReactionRulesClone[i] = bngReactionRules[i].deepClone();
79+
}
80+
}
81+
BNGReaction[] bngReactionsClone = null;
82+
if (bngReactions != null) {
83+
bngReactionsClone = new BNGReaction[bngReactions.length];
84+
for (int i = 0; i < bngReactions.length; i++) {
85+
bngReactionsClone[i] = bngReactions[i].deepClone();
86+
}
87+
}
88+
ObservableGroup[] bngObservableGroupsClone = null;
89+
if (bngObservableGroups != null){
90+
bngObservableGroupsClone = new ObservableGroup[bngObservableGroups.length];
91+
for (int i = 0; i < bngObservableGroups.length; i++) {
92+
bngObservableGroupsClone[i] = bngObservableGroups[i].deepClone();
93+
}
94+
}
95+
return new BNGOutputSpec(bngParamsClone, bngMoleculeTypesClone, bngSpeciesClone, bngReactionRulesClone, bngReactionsClone, bngObservableGroupsClone);
96+
}
5297
public BNGMolecule[] getBNGMolecules() {
5398
return bngMoleculeTypes;
5499
}

vcell-core/src/main/java/cbit/vcell/bionetgen/BNGParameter.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,8 @@ public void setValue(double argValue) {
6969
public String toString() {
7070
return new String(getName() + ";\t" + getValue());
7171
}
72+
73+
public BNGParameter deepClone() {
74+
return new BNGParameter(name, value);
75+
}
7276
}

vcell-core/src/main/java/cbit/vcell/bionetgen/BNGReaction.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,4 +354,22 @@ public String toStringShort() {
354354
}
355355
return reactionStr;
356356
}
357+
358+
359+
public BNGReaction deepClone() {
360+
BNGSpecies[] bngReactantsClone = new BNGSpecies[reactants.length];
361+
for (int i = 0; i < reactants.length; i++) {
362+
bngReactantsClone[i] = reactants[i].deepClone();
363+
}
364+
BNGSpecies[] bngProductsClone = new BNGSpecies[products.length];
365+
for (int i = 0; i < products.length; i++) {
366+
bngProductsClone[i] = products[i].deepClone();
367+
}
368+
Expression newParamExpression = paramExpression;
369+
if (newParamExpression != null) {
370+
newParamExpression = Expression.clone(paramExpression);
371+
}
372+
BNGReaction bngReactionClone = new BNGReaction(matchingKey, matchingKey, bngReactantsClone, bngProductsClone, newParamExpression, ruleName, bRuleReversed);
373+
return bngReactionClone;
374+
}
357375
}

vcell-core/src/main/java/cbit/vcell/bionetgen/BNGReactionRule.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,4 +186,20 @@ public String writeReaction() {
186186

187187
return reactionStr;
188188
}
189+
190+
public BNGReactionRule deepClone() {
191+
BNGParameter[] bngParamsClone = new BNGParameter[parameters.length];
192+
for (int i = 0; i < parameters.length; i++) {
193+
bngParamsClone[i] = parameters[i].deepClone();
194+
}
195+
BNGSpecies[] bngReactantsClone = new BNGSpecies[reactants.length];
196+
for (int i = 0; i < reactants.length; i++) {
197+
bngReactantsClone[i] = reactants[i].deepClone();
198+
}
199+
BNGSpecies[] bngProductsClone = new BNGSpecies[products.length];
200+
for (int i = 0; i < products.length; i++) {
201+
bngProductsClone[i] = products[i].deepClone();
202+
}
203+
return new BNGReactionRule(bngParamsClone, bngReactantsClone, bngProductsClone, isReversible());
204+
}
189205
}

0 commit comments

Comments
 (0)