use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class ObservableTableModel method propertyChange.
@Override
public void propertyChange(PropertyChangeEvent evt) {
super.propertyChange(evt);
Object source = evt.getSource();
// if (source == getModel().getRbmModelContainer()) {
if (source == getModel()) {
if (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_OBSERVABLE_LIST)) {
refreshData();
List<RbmObservable> oldValue = (List<RbmObservable>) evt.getOldValue();
if (oldValue != null) {
for (RbmObservable observable : oldValue) {
observable.removePropertyChangeListener(this);
SpeciesPattern speciesPattern = observable.getSpeciesPattern(0);
RbmUtils.removePropertyChangeListener(speciesPattern, this);
}
}
List<RbmObservable> newValue = (List<RbmObservable>) evt.getNewValue();
if (newValue != null) {
for (RbmObservable observable : newValue) {
observable.addPropertyChangeListener(this);
SpeciesPattern speciesPattern = observable.getSpeciesPattern(0);
RbmUtils.addPropertyChangeListener(speciesPattern, this);
}
}
} else if (evt.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST)) {
// we need this?
refreshData();
}
} else if (source instanceof RbmObservable) {
RbmObservable mt = (RbmObservable) source;
int changeRow = getRowIndex(mt);
if (changeRow >= 0) {
fireTableRowsUpdated(changeRow, changeRow);
}
// if (evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN_LIST)) {
// SpeciesPattern oldValue = (SpeciesPattern) evt.getOldValue();
// if (oldValue != null) {
// RbmUtils.removePropertyChangeListener(oldValue, this);
// }
// SpeciesPattern newValue = (SpeciesPattern) evt.getNewValue();
// if (newValue != null) {
// RbmUtils.addPropertyChangeListener(newValue, this);
// }
// }
} else if (source instanceof SpeciesPattern) {
fireTableRowsUpdated(0, getRowCount() - 1);
if (evt.getPropertyName().equals(SpeciesPattern.PROPERTY_NAME_MOLECULAR_TYPE_PATTERNS)) {
List<MolecularTypePattern> oldValue = (List<MolecularTypePattern>) evt.getOldValue();
if (oldValue != null) {
for (MolecularTypePattern mtp : oldValue) {
RbmUtils.removePropertyChangeListener(mtp, this);
}
}
List<MolecularTypePattern> newValue = (List<MolecularTypePattern>) evt.getNewValue();
if (newValue != null) {
for (MolecularTypePattern mtp : newValue) {
RbmUtils.addPropertyChangeListener(mtp, this);
}
}
}
} else if (source instanceof MolecularTypePattern) {
fireTableRowsUpdated(0, getRowCount() - 1);
if (evt.getPropertyName().equals(MolecularTypePattern.PROPERTY_NAME_COMPONENT_PATTERN_LIST)) {
List<MolecularComponentPattern> oldValue = (List<MolecularComponentPattern>) evt.getOldValue();
if (oldValue != null) {
for (MolecularComponentPattern mcp : oldValue) {
RbmUtils.removePropertyChangeListener(mcp, this);
}
}
List<MolecularComponentPattern> newValue = (List<MolecularComponentPattern>) evt.getNewValue();
if (newValue != null) {
for (MolecularComponentPattern mcp : newValue) {
RbmUtils.addPropertyChangeListener(mcp, this);
}
}
}
} else if (source instanceof MolecularComponentPattern) {
fireTableRowsUpdated(0, getRowCount() - 1);
if (source.equals(MolecularComponentPattern.PROPERTY_NAME_COMPONENT_STATE)) {
ComponentStateDefinition oldValue = (ComponentStateDefinition) evt.getOldValue();
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
}
ComponentStateDefinition newValue = (ComponentStateDefinition) evt.getNewValue();
if (newValue != null) {
newValue.addPropertyChangeListener(this);
}
}
} else if (evt.getSource() instanceof MolecularComponent) {
fireTableRowsUpdated(0, getRowCount() - 1);
} else if (evt.getSource() instanceof ComponentStateDefinition) {
fireTableRowsUpdated(0, getRowCount() - 1);
}
// updateStructureComboBox();
}
use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class ObservableTreeModel method propertyChange.
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_NAME)) {
nodeChanged(rootNode);
} else if (evt.getSource() == observable && evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_TYPE)) {
nodeChanged(rootNode);
} else if (evt.getPropertyName().equals("entityChange")) {
nodeChanged(rootNode);
} else {
populateTree();
Object source = evt.getSource();
if (source == observable) {
if (evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN_LIST)) {
List<SpeciesPattern> oldValue = (List<SpeciesPattern>) evt.getOldValue();
if (oldValue != null) {
for (SpeciesPattern sp : oldValue) {
RbmUtils.removePropertyChangeListener(sp, this);
}
}
List<SpeciesPattern> newValue = (List<SpeciesPattern>) evt.getNewValue();
if (newValue != null) {
for (SpeciesPattern sp : newValue) {
RbmUtils.addPropertyChangeListener(sp, this);
}
}
} else if (evt.getPropertyName().equals(RbmObservable.PROPERTY_NAME_SPECIES_PATTERN)) {
SpeciesPattern newValue = (SpeciesPattern) evt.getNewValue();
if (newValue != null) {
RbmUtils.addPropertyChangeListener(newValue, this);
}
}
} else if (source instanceof SpeciesPattern) {
if (evt.getPropertyName().equals(SpeciesPattern.PROPERTY_NAME_MOLECULAR_TYPE_PATTERNS)) {
List<MolecularTypePattern> oldValue = (List<MolecularTypePattern>) evt.getOldValue();
if (oldValue != null) {
for (MolecularTypePattern mtp : oldValue) {
RbmUtils.removePropertyChangeListener(mtp, this);
}
}
List<MolecularTypePattern> newValue = (List<MolecularTypePattern>) evt.getNewValue();
if (newValue != null) {
for (MolecularTypePattern mtp : newValue) {
RbmUtils.addPropertyChangeListener(mtp, this);
}
}
}
} else if (source instanceof MolecularTypePattern) {
if (evt.getPropertyName().equals(MolecularTypePattern.PROPERTY_NAME_COMPONENT_PATTERN_LIST)) {
List<MolecularComponentPattern> oldValue = (List<MolecularComponentPattern>) evt.getOldValue();
if (oldValue != null) {
for (MolecularComponentPattern mcp : oldValue) {
RbmUtils.removePropertyChangeListener(mcp, this);
}
}
List<MolecularComponentPattern> newValue = (List<MolecularComponentPattern>) evt.getNewValue();
if (newValue != null) {
for (MolecularComponentPattern mcp : newValue) {
RbmUtils.addPropertyChangeListener(mcp, this);
}
}
}
} else if (source instanceof MolecularComponentPattern) {
if (evt.getSource().equals(MolecularComponentPattern.PROPERTY_NAME_COMPONENT_STATE)) {
ComponentStateDefinition oldValue = (ComponentStateDefinition) evt.getOldValue();
if (oldValue != null) {
oldValue.removePropertyChangeListener(this);
}
ComponentStateDefinition newValue = (ComponentStateDefinition) evt.getNewValue();
if (newValue != null) {
newValue.addPropertyChangeListener(this);
}
}
}
}
}
use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class RbmObservable method gatherIssues.
public void gatherIssues(IssueContext issueContext, List<Issue> issueList) {
issueContext = issueContext.newChildContext(ContextType.RbmObservable, this);
if (name == null) {
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Name of Observable is null", Issue.SEVERITY_ERROR));
} else if (name.equals("")) {
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Name of Observable is empty", Issue.SEVERITY_WARNING));
} else {
if (speciesPatternList == null) {
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Observable '" + name + "' Species Pattern List is null", Issue.SEVERITY_ERROR));
} else if (speciesPatternList.isEmpty()) {
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Observable '" + name + "' Species Pattern List is empty", Issue.SEVERITY_WARNING));
} else {
for (SpeciesPattern sp : speciesPatternList) {
sp.checkSpeciesPattern(issueContext, issueList);
sp.gatherIssues(issueContext, issueList);
for (MolecularTypePattern mtpThis : sp.getMolecularTypePatterns()) {
checkComponentStateConsistency(issueContext, issueList, mtpThis);
}
}
}
if (type == null) {
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, "Observable '" + name + "' Type is null", Issue.SEVERITY_ERROR));
}
}
for (SpeciesPattern sp : speciesPatternList) {
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
String name = mtp.getMolecularType().getDisplayName().toLowerCase();
if (name.equals("trash")) {
String message = "'Trash' is a reserved NFSim keyword and it cannot be used as an observable.";
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
}
}
}
// ---------------------------------------- polymer notation restrictions
// polymer notation may only contain one species pattern and one type of molecule
boolean polymerAllowedSingle = true;
// ---------------,,---------------- molecules in trivial state (question marks for bonds and states)
boolean polymerAllowedSimple = true;
if (speciesPatternList.size() > 1) {
polymerAllowedSingle = false;
}
if (speciesPatternList.size() > 0) {
SpeciesPattern sp = speciesPatternList.get(0);
if (sp != null && !sp.getMolecularTypePatterns().isEmpty()) {
if (sp.getMolecularTypePatterns().size() > 1) {
polymerAllowedSingle = false;
} else {
MolecularTypePattern mtp = sp.getMolecularTypePatterns().get(0);
if (mtp != null) {
for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
if (mcp.isbVisible()) {
polymerAllowedSimple = false;
break;
}
}
}
}
}
}
if (!polymerAllowedSingle && sequence != Sequence.Multimolecular) {
String message = "Polymer may only be specified for Observable containing a single Molecule.";
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
} else if (!polymerAllowedSimple && sequence != Sequence.Multimolecular) {
String message = "Polymer may only be specified for Observable with all bonds set to 'Possible' and all States set to 'Any'";
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
}
if (sequence != Sequence.Multimolecular && type == ObservableType.Molecules) {
String message = "The Polymer Observable must be of type 'Species'.";
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.ERROR));
}
if (name.equalsIgnoreCase("Rg3")) {
System.out.println(name);
}
for (SpeciesPattern sp : speciesPatternList) {
// we look for species patterns where the polymer notation would be more suitable
Set<String> moleculeNames = new HashSet<>();
boolean isTrivial = true;
for (MolecularTypePattern mtp : sp.getMolecularTypePatterns()) {
moleculeNames.add(mtp.getMolecularType().getDisplayName());
for (MolecularComponentPattern mcp : mtp.getComponentPatternList()) {
if (mcp.isbVisible()) {
isTrivial = false;
// we may have more than 1 sp in the observable, check them all
continue;
}
}
}
if (isTrivial && sp.getMolecularTypePatterns().size() > 1 && moleculeNames.size() == 1) {
String message = "Please use the Polymer notation (i.e. " + moleculeNames.toArray()[0] + "()>" + (sp.getMolecularTypePatterns().size() - 1) + " ) ";
message += "instead of " + sp.toString();
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, message, Issue.Severity.WARNING));
// if we find one sp that is suitable for polymer notation we stop here and don't check other sp
break;
}
}
}
use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class RbmObservable 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;
}
MolecularType mtThat = mtpThis.getMolecularType();
for (MolecularComponentPattern mcpThis : mtpThis.getComponentPatternList()) {
if (mcpThis.isImplied()) {
// continue;
}
ComponentStatePattern cspThis = mcpThis.getComponentStatePattern();
String mcNameThis = mcpThis.getMolecularComponent().getName();
if (cspThis == null && mcpThis.getMolecularComponent().getComponentStateDefinitions().size() > 0) {
// String msg = "Component pattern " + mcNameThis + " is in no State while the component has possible States defined.";
String msg = "One of the possible States must be chosen for " + MolecularComponentPattern.typeName + " " + mcNameThis + ".";
issueList.add(new Issue(this, mcpThis, issueContext, IssueCategory.Identifiers, msg, null, Issue.SEVERITY_WARNING));
}
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, null, 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, issueContext, IssueCategory.Identifiers, 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 + " " + MolecularComponentPattern.typeName + " " + mcNameThis;
issueList.add(new Issue(this, issueContext, IssueCategory.Identifiers, msg, Issue.SEVERITY_WARNING));
}
}
}
}
}
}
use of org.vcell.model.rbm.MolecularComponentPattern in project vcell by virtualcell.
the class RbmObservable method deleteStateFromPatterns.
public boolean deleteStateFromPatterns(MolecularType mt, MolecularComponent mc, ComponentStateDefinition csd) {
for (SpeciesPattern sp : getSpeciesPatternList()) {
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 {
// 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);
}
}
}
}
}
}
return true;
}
Aggregations