use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class ReactionRule method findStateUsage.
public void findStateUsage(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd, Map<String, Pair<Displayable, SpeciesPattern>> usedHere) {
for (ProductPattern pp : getProductPatterns()) {
SpeciesPattern sp = pp.getSpeciesPattern();
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getMolecularType() == mt) {
List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
for (MolecularComponentPattern mcp : componentPatterns) {
if (mcp.isImplied()) {
// we don't care about these
continue;
}
if (mcp.getMolecularComponent() == mc) {
// found mc in use
// now let's look at component state definition
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp == null) {
continue;
}
if (csp.getComponentStateDefinition() == csd) {
String key = getDisplayType() + getDisplayName() + sp.getDisplayName();
usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
}
}
}
}
}
}
for (ReactantPattern rp : getReactantPatterns()) {
SpeciesPattern sp = rp.getSpeciesPattern();
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getMolecularType() == mt) {
List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
for (MolecularComponentPattern mcp : componentPatterns) {
if (mcp.isImplied()) {
continue;
}
if (mcp.getMolecularComponent() == mc) {
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp == null) {
continue;
}
if (csp.getComponentStateDefinition() == csd) {
String key = getDisplayType() + getDisplayName() + sp.getDisplayName();
usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
}
}
}
}
}
}
}
use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class ReactionRule method duplicate.
public static ReactionRule duplicate(ReactionRule oldRule, Structure s) throws ExpressionBindingException {
Model m = oldRule.getModel();
boolean bR = oldRule.isReversible();
String newName = ReactionRule.deriveReactionName(oldRule);
ReactionRule newRule = new ReactionRule(m, newName, s, bR);
RateLawType rateLawType = oldRule.getKineticLaw().getRateLawType();
if (rateLawType != RateLawType.MassAction) {
throw new RuntimeException("Only Mass Action Kinetics supported at this time, " + ReactionRule.typeName + " \"" + oldRule.getName() + "\" uses kinetic law type \"" + rateLawType.toString() + "\"");
}
RbmKineticLaw kineticLaw = new RbmKineticLaw(newRule, rateLawType);
RbmKineticLaw.duplicate(kineticLaw, oldRule);
for (ReactantPattern oldrp : oldRule.getReactantPatterns()) {
SpeciesPattern newsp = new SpeciesPattern(m, oldrp.getSpeciesPattern());
ReactantPattern newrp = new ReactantPattern(newsp, oldrp.getStructure());
// don't try to resolve matches or bonds, we want to mirror whatever is in the old rule
newRule.addReactant(newrp, false, false);
}
for (ProductPattern oldpp : oldRule.getProductPatterns()) {
SpeciesPattern newsp = new SpeciesPattern(m, oldpp.getSpeciesPattern());
ProductPattern newpp = new ProductPattern(newsp, oldpp.getStructure());
newRule.addProduct(newpp, false, false);
}
newRule.setKineticLaw(kineticLaw);
kineticLaw.bind(newRule);
return newRule;
}
use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class ReactionRule method deleteStateFromPatterns.
public boolean deleteStateFromPatterns(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd) {
for (ProductPattern pp : getProductPatterns()) {
SpeciesPattern sp = pp.getSpeciesPattern();
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getMolecularType() == mt) {
List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
for (MolecularComponentPattern mcp : componentPatterns) {
if (!(mcp.getMolecularComponent() == mc)) {
// not our mc
continue;
}
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp == null) {
continue;
}
if (csp.isAny()) {
if (mc.getComponentStateDefinitions().size() == 1) {
// we are about to delete the last possible state, so we set the ComponentStatePattern to null
mcp.setComponentStatePattern(null);
}
continue;
}
if (csp.getComponentStateDefinition() == csd) {
if (mc.getComponentStateDefinitions().size() == 1) {
// we are about to delete the last possible state, so we set the ComponentStatePattern to null
mcp.setComponentStatePattern(null);
} else {
// some other state is still available, we set the ComponentStatePattern to Any and let the user deal with it
csp = new ComponentStatePattern();
mcp.setComponentStatePattern(csp);
}
}
}
}
}
}
for (ReactantPattern rp : getReactantPatterns()) {
SpeciesPattern sp = rp.getSpeciesPattern();
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getMolecularType() == mt) {
List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
for (MolecularComponentPattern mcp : componentPatterns) {
if (!(mcp.getMolecularComponent() == mc)) {
continue;
}
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp == null) {
continue;
}
if (csp.isAny()) {
if (mc.getComponentStateDefinitions().size() == 1) {
mcp.setComponentStatePattern(null);
}
continue;
}
if (csp.getComponentStateDefinition() == csd) {
if (mc.getComponentStateDefinitions().size() == 1) {
mcp.setComponentStatePattern(null);
} else {
csp = new ComponentStatePattern();
mcp.setComponentStatePattern(csp);
}
}
}
}
}
}
return true;
}
use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class SpeciesContext method findComponentUsage.
public void findComponentUsage(MolecularType mt, MolecularComponent mc, Map<String, Pair<Displayable, SpeciesPattern>> usedHere) {
if (!hasSpeciesPattern()) {
return;
}
SpeciesPattern sp = getSpeciesPattern();
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getMolecularType() == mt) {
List<MolecularComponentPattern> componentPatterns = mtp.getComponentPatternList();
for (MolecularComponentPattern mcp : componentPatterns) {
if (mcp.getMolecularComponent() == mc) {
// here all components are always in use
if (mcp.getBond() != null) {
// we only care about the components with a bond
String key = sp.getDisplayName();
key = getDisplayType() + getDisplayName() + key;
usedHere.put(key, new Pair<Displayable, SpeciesPattern>(this, sp));
}
}
}
}
}
}
use of org.vcell.model.rbm.SpeciesPattern in project vcell by virtualcell.
the class SpeciesContext method parseSpeciesPatternString.
public void parseSpeciesPatternString(Model model) {
if (speciesPatternString.equalsIgnoreCase("null")) {
System.out.println("Species Pattern String is 'NULL'.");
return;
}
if (speciesPatternString != null) {
try {
if (speciesPattern != null) {
System.out.println("Species pattern already exists: " + speciesPattern.toString());
return;
}
SpeciesPattern sp = RbmUtils.parseSpeciesPattern(speciesPatternString, model);
setSpeciesPattern(sp);
} catch (ParseException e) {
e.printStackTrace();
throw new RuntimeException("Bad format for repository species pattern string: " + e.getMessage());
}
}
}
Aggregations