use of org.vcell.model.rbm.MolecularComponent 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.MolecularComponent in project vcell by virtualcell.
the class SpeciesContext method checkComponentStateConsistency.
public void checkComponentStateConsistency(IssueContext issueContext, List<Issue> issueList, MolecularTypePattern mtpThis) {
issueContext = issueContext.newChildContext(ContextType.SpeciesContext, this);
MolecularType mtThat = mtpThis.getMolecularType();
for (MolecularComponentPattern mcpThis : mtpThis.getComponentPatternList()) {
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, issueContext, IssueCategory.Identifiers, 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, null, 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 = MolecularComponentPattern.typeName + " " + mcNameThis + " must be in an explicit State.";
issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, null, Issue.Severity.ERROR));
} else {
String csdNameThis = cspThis.getComponentStateDefinition().getName();
if (csdNameThis.isEmpty() || (mcThat.getComponentStateDefinition(csdNameThis) == null)) {
String msg = "Invalid State " + csdNameThis + " for " + MolecularComponentPattern.typeName + " " + mcNameThis;
issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, null, Issue.SEVERITY_WARNING));
}
}
}
}
}
}
use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class RbmMolecularTypeTreeCellEditor method getTreeCellEditorComponent.
@Override
public Component getTreeCellEditorComponent(JTree tree, Object value, boolean isSelected, boolean expanded, boolean leaf, int row) {
Component component = null;
realEditor = defaultCellEditor;
if (value instanceof BioModelNode) {
BioModelNode node = (BioModelNode) value;
Object userObject = node.getUserObject();
String text = null;
Icon icon = null;
if (userObject instanceof MolecularType) {
text = ((MolecularType) userObject).getName();
icon = VCellIcons.rbmMolecularTypeIcon;
} else if (userObject instanceof MolecularComponent) {
BioModelNode parentNode = (BioModelNode) node.getParent();
Object parentObject = parentNode == null ? null : parentNode.getUserObject();
icon = VCellIcons.rbmComponentErrorIcon;
text = ((MolecularComponent) userObject).getName();
} else if (userObject instanceof ComponentStateDefinition) {
text = ((ComponentStateDefinition) userObject).getName();
icon = VCellIcons.rbmComponentStateIcon;
} else {
System.out.println("unexpected thing here " + userObject);
}
renderer.setOpenIcon(icon);
renderer.setClosedIcon(icon);
renderer.setLeafIcon(icon);
component = super.getTreeCellEditorComponent(tree, value, isSelected, expanded, leaf, row);
if (editingComponent instanceof JTextField) {
JTextField textField = (JTextField) editingComponent;
textField.setText(text);
}
}
return component;
}
use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class RbmMolecularTypeTreeCellRenderer method getTreeCellRendererComponent.
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
setBorder(null);
if (value instanceof BioModelNode) {
BioModelNode node = (BioModelNode) value;
Object userObject = node.getUserObject();
String text = null;
String toolTip = null;
Icon icon = null;
if (userObject instanceof MolecularType) {
MolecularType mt = (MolecularType) userObject;
text = toHtml(mt, true);
toolTip = toHtmlWithTip(mt, true);
if (owner == null) {
icon = VCellIcons.rbmMolecularTypeSimpleIcon;
;
} else {
Graphics gc = owner.getGraphics();
icon = new MolecularTypeSmallShape(1, 4, mt, null, gc, mt, null, issueManager);
}
} else if (userObject instanceof MolecularComponent) {
BioModelNode parentNode = (BioModelNode) node.getParent();
MolecularComponent mc = (MolecularComponent) userObject;
text = toHtml(mc, true);
toolTip = toHtmlWithTip(mc, true);
icon = VCellIcons.rbmComponentGreenIcon;
if (mc.getComponentStateDefinitions().size() > 0) {
icon = VCellIcons.rbmComponentGreenStateIcon;
}
// here is how to set the cell minimum size !!!
FontMetrics fm = getFontMetrics(getFont());
int width = fm.stringWidth(text);
setMinimumSize(new Dimension(width + 50, fm.getHeight() + 5));
} else if (userObject instanceof ComponentStateDefinition) {
ComponentStateDefinition cs = (ComponentStateDefinition) userObject;
text = toHtml(cs);
toolTip = toHtmlWithTip(cs);
icon = VCellIcons.rbmComponentStateIcon;
} else {
System.out.println("unknown thingie " + userObject);
}
setText(text);
setIcon(icon);
setToolTipText(toolTip == null ? text : toolTip);
}
return this;
}
use of org.vcell.model.rbm.MolecularComponent in project vcell by virtualcell.
the class RbmTreeCellRenderer method toHtml.
public static final String toHtml(MolecularComponentPattern mcp, boolean bShowWords) {
String text = (bShowWords ? MolecularComponent.typeName : "") + " <b>" + mcp.getMolecularComponent().getName() + "</b>";
MolecularComponent mc = mcp.getMolecularComponent();
return "<html> " + text + "</html>";
}
Aggregations