use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class ObservableTreeModel method valueForPathChanged.
@Override
public void valueForPathChanged(TreePath path, Object newValue) {
Object obj = path.getLastPathComponent();
if (obj == null || !(obj instanceof BioModelNode)) {
return;
}
BioModelNode selectedNode = (BioModelNode) obj;
BioModelNode parentNode = (BioModelNode) selectedNode.getParent();
Object userObject = selectedNode.getUserObject();
try {
if (newValue instanceof String) {
String inputString = (String) newValue;
if (inputString == null || inputString.length() == 0) {
return;
}
String mangled = TokenMangler.fixTokenStrict(inputString);
if (!mangled.equals(inputString)) {
String errMsg = ((Displayable) userObject).getDisplayType() + " '" + inputString + "' not legal identifier, try '" + mangled + "'";
throw new RuntimeException(errMsg);
}
if (userObject instanceof RbmObservable) {
// TODO: untested!!!
((RbmObservable) userObject).setName(inputString);
}
} else if (newValue instanceof MolecularComponentPattern) {
MolecularComponentPattern newMcp = (MolecularComponentPattern) newValue;
Object parentObject = parentNode == null ? null : parentNode.getUserObject();
if (parentObject instanceof MolecularTypePattern) {
MolecularTypePattern mtp = (MolecularTypePattern) parentObject;
MolecularComponent mc = newMcp.getMolecularComponent();
MolecularComponentPattern mcp = mtp.getMolecularComponentPattern(mc);
mcp.setComponentStatePattern(newMcp.getComponentStatePattern());
BondType bp = mcp.getBondType();
BondType newbp = newMcp.getBondType();
mcp.setBondType(newbp);
// specified -> specified
if (bp == BondType.Specified && newbp == BondType.Specified) {
// bond didn't change
} else if (bp == BondType.Specified && newbp != BondType.Specified) {
// specified -> non specified
// change the partner to possible
mcp.getBond().molecularComponentPattern.setBondType(BondType.Possible);
mcp.setBond(null);
} else if (bp != BondType.Specified && newbp == BondType.Specified) {
// non specified -> specified
int newBondId = newMcp.getBondId();
mcp.setBondId(newBondId);
mcp.setBond(newMcp.getBond());
mcp.getBond().molecularComponentPattern.setBondId(newBondId);
for (SpeciesPattern sp : observable.getSpeciesPatternList()) {
sp.resolveBonds();
}
} else {
}
}
}
} catch (Exception ex) {
DialogUtils.showErrorDialog(ownerTree, ex.getMessage());
}
}
use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class RulebasedMathMapping method addSpeciesPatterns.
private HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> addSpeciesPatterns(Domain domain, List<ReactionRule> rrList) throws MathException {
// Particle Molecular Types
//
Model model = getSimulationContext().getModel();
List<RbmObservable> observableList = model.getRbmModelContainer().getObservableList();
List<MolecularType> molecularTypeList = model.getRbmModelContainer().getMolecularTypeList();
for (MolecularType molecularType : molecularTypeList) {
ParticleMolecularType particleMolecularType = new ParticleMolecularType(molecularType.getName());
for (MolecularComponent molecularComponent : molecularType.getComponentList()) {
String pmcName = molecularComponent.getName();
String pmcId = particleMolecularType.getName() + "_" + molecularComponent.getName();
ParticleMolecularComponent particleMolecularComponent = new ParticleMolecularComponent(pmcId, pmcName);
for (ComponentStateDefinition componentState : molecularComponent.getComponentStateDefinitions()) {
ParticleComponentStateDefinition pcsd = particleMolecularComponent.getComponentStateDefinition(componentState.getName());
if (pcsd == null) {
particleMolecularComponent.addComponentStateDefinition(new ParticleComponentStateDefinition(componentState.getName()));
}
}
particleMolecularType.addMolecularComponent(particleMolecularComponent);
}
if (!molecularType.isAnchorAll()) {
List<String> anchorList = new ArrayList<>();
for (Structure struct : molecularType.getAnchors()) {
anchorList.add(struct.getName());
}
particleMolecularType.setAnchorList(anchorList);
}
mathDesc.addParticleMolecularType(particleMolecularType);
}
//
// Assemble list of all Species Patterns (from observables, reaction rules, and seed species).
//
// linked hash set maintains insertion order
LinkedHashMap<SpeciesPattern, Structure> speciesPatternStructureMap = new LinkedHashMap<SpeciesPattern, Structure>();
for (RbmObservable observable : observableList) {
for (SpeciesPattern speciesPattern : observable.getSpeciesPatternList()) {
speciesPatternStructureMap.put(speciesPattern, observable.getStructure());
}
}
for (ReactionRule reactionRule : rrList) {
for (ReactantPattern rp : reactionRule.getReactantPatterns()) {
speciesPatternStructureMap.put(rp.getSpeciesPattern(), rp.getStructure());
}
for (ProductPattern pp : reactionRule.getProductPatterns()) {
speciesPatternStructureMap.put(pp.getSpeciesPattern(), pp.getStructure());
}
}
for (SpeciesContext sc : model.getSpeciesContexts()) {
if (!sc.hasSpeciesPattern()) {
continue;
}
speciesPatternStructureMap.put(sc.getSpeciesPattern(), sc.getStructure());
}
//
// add list of unique speciesPatterns
//
HashMap<String, VolumeParticleSpeciesPattern> speciesPatternVCMLMap = new HashMap<String, VolumeParticleSpeciesPattern>();
HashMap<SpeciesPattern, VolumeParticleSpeciesPattern> speciesPatternMap = new HashMap<SpeciesPattern, VolumeParticleSpeciesPattern>();
String speciesPatternName = "speciesPattern0";
for (SpeciesPattern speciesPattern : speciesPatternStructureMap.keySet()) {
VolumeParticleSpeciesPattern volumeParticleSpeciesPattern = new VolumeParticleSpeciesPattern(speciesPatternName, domain, speciesPatternStructureMap.get(speciesPattern).getName());
for (MolecularTypePattern molecularTypePattern : speciesPattern.getMolecularTypePatterns()) {
ParticleMolecularType particleMolecularType = mathDesc.getParticleMolecularType(molecularTypePattern.getMolecularType().getName());
ParticleMolecularTypePattern particleMolecularTypePattern = new ParticleMolecularTypePattern(particleMolecularType);
String participantMatchLabel = molecularTypePattern.getParticipantMatchLabel();
if (molecularTypePattern.getParticipantMatchLabel() != null) {
particleMolecularTypePattern.setMatchLabel(participantMatchLabel);
}
for (MolecularComponentPattern molecularComponentPattern : molecularTypePattern.getComponentPatternList()) {
MolecularComponent molecularComponent = molecularComponentPattern.getMolecularComponent();
ParticleMolecularComponent particleMolecularComponent = particleMolecularType.getMolecularComponent(molecularComponent.getName());
ParticleMolecularComponentPattern particleMolecularComponentPattern = new ParticleMolecularComponentPattern(particleMolecularComponent);
ComponentStatePattern componentState = molecularComponentPattern.getComponentStatePattern();
if (componentState != null) {
if (componentState.isAny()) {
ParticleComponentStatePattern pcsp = new ParticleComponentStatePattern();
particleMolecularComponentPattern.setComponentStatePattern(pcsp);
} else {
String name = componentState.getComponentStateDefinition().getName();
ParticleComponentStateDefinition pcsd = particleMolecularComponent.getComponentStateDefinition(name);
// ParticleComponentStateDefinition pcsd = new ParticleComponentStateDefinition(componentState.getComponentStateDefinition().getName());
// particleMolecularComponent.addComponentStateDefinition(pcsd);
ParticleComponentStatePattern pcsp = new ParticleComponentStatePattern(pcsd);
particleMolecularComponentPattern.setComponentStatePattern(pcsp);
}
} else {
ParticleComponentStatePattern pcsp = new ParticleComponentStatePattern();
particleMolecularComponentPattern.setComponentStatePattern(pcsp);
}
switch(molecularComponentPattern.getBondType()) {
case Specified:
{
particleMolecularComponentPattern.setBondType(ParticleBondType.Specified);
particleMolecularComponentPattern.setBondId(molecularComponentPattern.getBondId());
break;
}
case Exists:
{
particleMolecularComponentPattern.setBondType(ParticleBondType.Exists);
particleMolecularComponentPattern.setBondId(-1);
break;
}
case None:
{
particleMolecularComponentPattern.setBondType(ParticleBondType.None);
particleMolecularComponentPattern.setBondId(-1);
break;
}
case Possible:
{
particleMolecularComponentPattern.setBondType(ParticleBondType.Possible);
particleMolecularComponentPattern.setBondId(-1);
break;
}
}
particleMolecularTypePattern.addMolecularComponentPattern(particleMolecularComponentPattern);
}
volumeParticleSpeciesPattern.addMolecularTypePattern(particleMolecularTypePattern);
}
String speciesPatternVCML = volumeParticleSpeciesPattern.getVCML("tempName");
VolumeParticleSpeciesPattern uniqueVolumeParticleSpeciesPattern = speciesPatternVCMLMap.get(speciesPatternVCML);
if (uniqueVolumeParticleSpeciesPattern == null) {
speciesPatternVCMLMap.put(speciesPatternVCML, volumeParticleSpeciesPattern);
speciesPatternName = TokenMangler.getNextEnumeratedToken(speciesPatternName);
speciesPatternMap.put(speciesPattern, volumeParticleSpeciesPattern);
} else {
speciesPatternMap.put(speciesPattern, uniqueVolumeParticleSpeciesPattern);
}
}
return speciesPatternMap;
}
use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class RbmObservable method resolveStates.
// TODO: this will have to go once we get rid of ComponentStatePattern
// use as a stopgap measure to eliminate a bug where the ComponentStatePattern is null
// instead of being Any (which happens when the MolecularComponent has states defined)
private void resolveStates() {
for (SpeciesPattern sp : speciesPatternList) {
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
if (mcp.getComponentStatePattern() == null && mcp.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
ComponentStatePattern csp = new ComponentStatePattern();
mcp.setComponentStatePattern(csp);
}
}
}
}
}
use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class RbmObservable method findStateUsage.
public void findStateUsage(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd, Map<String, Pair<Displayable, SpeciesPattern>> usedHere) {
for (SpeciesPattern sp : getSpeciesPatternList()) {
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 = 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 ReactionRule method getReactantComponentState.
public ComponentStatePattern getReactantComponentState(MolecularComponentPattern mcpProduct) {
if (mcpProduct.getMolecularComponent().getComponentStateDefinitions().isEmpty()) {
return null;
}
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.getComponentStatePattern();
}
return null;
}
Aggregations