use of org.vcell.model.rbm.ComponentStatePattern 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.ComponentStatePattern in project vcell by virtualcell.
the class ReactionRule method checkComponentStateConsistency.
public void checkComponentStateConsistency(IssueContext issueContext, List<Issue> issueList, MolecularTypePattern mtpThis) {
if (issueList == null) {
// this may be called during parsing before the model is consistent
return;
}
issueContext = issueContext.newChildContext(ContextType.ReactionRule, this);
MolecularType mtThat = mtpThis.getMolecularType();
for (MolecularComponentPattern mcpThis : mtpThis.getComponentPatternList()) {
if (mcpThis.isImplied()) {
continue;
}
ComponentStatePattern cspThis = mcpThis.getComponentStatePattern();
String mcNameThis = mcpThis.getMolecularComponent().getName();
MolecularComponent[] mcThatList = mtThat.getMolecularComponents(mcNameThis);
if (mcThatList.length == 0) {
System.out.println("we already fired an issue about component missing");
// nothing to do here, we already fired an issue about component missing
continue;
} else if (mcThatList.length > 1) {
String msg = "Multiple " + MolecularComponent.typeName + "s with the same name are not yet supported.";
issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, msg, Issue.SEVERITY_ERROR));
} else {
// found exactly 1 component
MolecularComponent mcThat = mcThatList[0];
List<ComponentStateDefinition> csdListThat = mcThat.getComponentStateDefinitions();
if (csdListThat.size() == 0) {
// component has no states, we check if mcpThis has any states... it shouldn't
if (cspThis == null) {
// all is well
continue;
}
if (!cspThis.isAny() || (cspThis.getComponentStateDefinition() != null)) {
String msg = MolecularComponentPattern.typeName + " " + mcNameThis + " is in an invalid State.";
issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, msg, Issue.SEVERITY_WARNING));
}
} else {
// we check if mcpThis has any of these states... it should!
if ((cspThis == null) || cspThis.isAny() || (cspThis.getComponentStateDefinition() == null)) {
// String msg = "Component pattern " + mcNameThis + " must be in an explicit State.";
// issueList.add(new Issue(this, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
} else {
String csdNameThis = cspThis.getComponentStateDefinition().getName();
if (csdNameThis.isEmpty() || (mcThat.getComponentStateDefinition(csdNameThis) == null)) {
String msg = "Invalid State " + csdNameThis + " for component pattern " + mcNameThis;
issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, msg, Issue.SEVERITY_WARNING));
}
}
}
}
}
}
use of org.vcell.model.rbm.ComponentStatePattern 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.ComponentStatePattern in project vcell by virtualcell.
the class SpeciesContext method findStateUsage.
public void findStateUsage(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd, 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 some state is always in use if available
ComponentStatePattern csp = mcp.getComponentStatePattern();
if (csp == null) {
System.out.println("This component " + mc.getName() + " should have had some State specified.");
continue;
}
if ((csp.getComponentStateDefinition() == csd) && (mcp.getBond() != null)) {
// we only care if there's 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.ComponentStatePattern in project vcell by virtualcell.
the class SpeciesContext method deleteStateFromPatterns.
public boolean deleteStateFromPatterns(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd) {
if (!hasSpeciesPattern()) {
return true;
}
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)) {
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) {
// we are about to delete the last possible state, so we set the ComponentStatePattern to null
mcp.setComponentStatePattern(null);
} else {
// set to Any (may result in an Issue being raised)
csp = new ComponentStatePattern();
mcp.setComponentStatePattern(csp);
}
}
}
}
}
return true;
}
Aggregations