use of org.vcell.model.rbm.MolecularComponentPattern 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.MolecularComponentPattern in project vcell by virtualcell.
the class ReactionRule method getReactantComponentBondType.
public BondType getReactantComponentBondType(MolecularComponentPattern mcpProduct) {
MolecularTypePattern mtpProduct = getProductMoleculeOfComponent(mcpProduct);
MolecularTypePattern mtpReactant = getMatchingReactantMolecule(mtpProduct);
if (mtpReactant == null) {
// possible if this product has no matching explicit or implicit reactant
return null;
}
for (MolecularComponentPattern mcpReactant : mtpReactant.getComponentPatternList()) {
if (mcpReactant.getMolecularComponent() != mcpProduct.getMolecularComponent()) {
continue;
}
return mcpReactant.getBondType();
}
return null;
}
use of org.vcell.model.rbm.MolecularComponentPattern 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.MolecularComponentPattern in project vcell by virtualcell.
the class SpeciesContext method checkMolecularTypeConsistency.
// I think this should never fire issues, that's why I keep issue severity to error to force further investigation
// TODO: oct 30, 2015: hasn't fired in 9 months, we replace the issues with exception just to protect ourselves against regressions
private void checkMolecularTypeConsistency(IssueContext issueContext, List<Issue> issueList, MolecularType mtThat, MolecularTypePattern mtpThis) {
issueContext = issueContext.newChildContext(ContextType.SpeciesContext, this);
Map<String, MolecularComponent> hashThat = new HashMap<String, MolecularComponent>();
Map<String, MolecularComponent> hashThis = new HashMap<String, MolecularComponent>();
for (MolecularComponent mcThat : mtThat.getComponentList()) {
hashThat.put(mcThat.getName(), mcThat);
}
for (MolecularComponentPattern mcpThis : mtpThis.getComponentPatternList()) {
hashThis.put(mcpThis.getMolecularComponent().getName(), mcpThis.getMolecularComponent());
}
Iterator<Entry<String, MolecularComponent>> it = hashThat.entrySet().iterator();
while (it.hasNext()) {
String key = ((Map.Entry<String, MolecularComponent>) it.next()).getKey();
if (hashThis.containsKey(key)) {
it.remove();
hashThis.remove(key);
}
}
// any component still present in hashThis it means that it has been deleted in the molecular types definition and is now invalid
for (String key : hashThat.keySet()) {
String msg = "All components in the " + mtThat.getDisplayType() + " definition must be present. Missing: " + key + ".";
throw new RuntimeException(msg);
// issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_ERROR));
}
for (String key : hashThis.keySet()) {
String msg = "Component " + key + " is no longer defined for the " + mtThat.getDisplayType() + " and must be removed.";
throw new RuntimeException(msg);
// issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_ERROR));
}
}
use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class SpeciesContext method checkBondsSufficiency.
private void checkBondsSufficiency(IssueContext issueContext, List<Issue> issueList, SpeciesPattern sp) {
if (sp.getMolecularTypePatterns().size() < 2) {
return;
}
int numberOfMolecularTypeCandidates = 0;
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
if (mtp.getComponentPatternList().size() > 0) {
numberOfMolecularTypeCandidates++;
}
}
if (numberOfMolecularTypeCandidates < 2) {
// we need at least 2 molecular types with at least 1 component each
return;
}
boolean atLeastOneBad = false;
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
boolean bondSpecifiedExists = false;
for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
if (mcp.getBondType() == BondType.Specified) {
Bond b = mcp.getBond();
if (b != null) {
bondSpecifiedExists = true;
break;
}
}
}
if (!bondSpecifiedExists) {
atLeastOneBad = true;
}
}
if (atLeastOneBad) {
String msg = "Each Molecular Pattern of the Species Pattern " + sp.toString() + " needs at least one explicit Bond.\n";
IssueSource parent = issueContext.getContextObject();
issueList.add(new Issue(parent, issueContext, IssueCategory.Identifiers, msg, Issue.Severity.ERROR));
}
}
Aggregations