use of org.vcell.model.rbm.MolecularType 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.MolecularType in project vcell by virtualcell.
the class ReactionRule method resolveMatches.
private void resolveMatches() {
// for each molecular type, make a lists of all corresponding molecular type patterns, one for reactants, one for products
Map<MolecularType, List<MolecularTypePattern>> reactantMap = new LinkedHashMap<MolecularType, List<MolecularTypePattern>>();
Map<MolecularType, List<MolecularTypePattern>> productMap = new LinkedHashMap<MolecularType, List<MolecularTypePattern>>();
for (MolecularType mt : model.getRbmModelContainer().getMolecularTypeList()) {
List<MolecularTypePattern> mtpReactantList = populateMaps(mt, ReactionRuleParticipantType.Reactant);
reactantMap.put(mt, mtpReactantList);
List<MolecularTypePattern> mtpProductList = populateMaps(mt, ReactionRuleParticipantType.Product);
productMap.put(mt, mtpProductList);
}
// we'll build a list with all tha mapped pairs so that we won't have to worry about them
Map<String, MolecularTypePattern> pairAlreadyMapped = new LinkedHashMap<String, MolecularTypePattern>();
// if, for a certain MolecularType, we have 0 or 1 MoleculartypePatterns both in reactant and product we ignore because it's trivial
for (MolecularType mt : model.getRbmModelContainer().getMolecularTypeList()) {
if (reactantMap.get(mt).size() < 2 && productMap.get(mt).size() < 2) {
// we make sure that the match flag is "*" (indifferent) for these
if (reactantMap.get(mt).size() == 1) {
reactantMap.get(mt).get(0).setParticipantMatchLabel("*");
}
if (productMap.get(mt).size() == 1) {
productMap.get(mt).get(0).setParticipantMatchLabel("*");
}
continue;
}
// those patterns with a valid match we take out from this lists and we put them in separate lists
// if we find orphans either in the reactant or product list we set them to indifferent / any
List<MolecularTypePattern> mtpReactantList = reactantMap.get(mt);
List<MolecularTypePattern> mtpProductList = productMap.get(mt);
List<MolecularTypePattern> mtpReactantsToRemove = new ArrayList<MolecularTypePattern>();
for (MolecularTypePattern mtpr : mtpReactantList) {
if (mtpr.hasExplicitParticipantMatch()) {
String matchKey = mtpr.getParticipantMatchLabel();
// we look for a match in the products
MolecularTypePattern mtpp = findMatch(matchKey, mtpProductList);
if (mtpp == null) {
// no product has the matching key, so this reactant must be orphan
// we set it to any
mtpr.setParticipantMatchLabel("*");
} else {
// we add this pair to the map of already mapped pairs and take it out from here
if (pairAlreadyMapped.containsKey(matchKey)) {
// key already in use, we generate a new one
matchKey = generateNewMatchKey(pairAlreadyMapped);
mtpr.setParticipantMatchLabel(matchKey);
mtpp.setParticipantMatchLabel(matchKey);
}
// we'll remove the reactants after finishing the iterations
mtpReactantsToRemove.add(mtpr);
mtpProductList.remove(mtpp);
pairAlreadyMapped.put(matchKey, mtpr);
}
}
}
for (MolecularTypePattern mtpr : mtpReactantsToRemove) {
// now we can remove the reactants without generating concurrent exceptions
mtpReactantList.remove(mtpr);
}
// mtpProductList may still contain orphans with match flag set to something not "any", we need to fix them
for (MolecularTypePattern mtpp : mtpProductList) {
if (mtpp.hasExplicitParticipantMatch()) {
String matchKey = mtpp.getParticipantMatchLabel();
// we look for a match in the reactants
MolecularTypePattern mtpr = findMatch(matchKey, mtpReactantList);
if (mtpr == null) {
// no reactant has the matching key, so this product must be orphan
// we set it to any
mtpp.setParticipantMatchLabel("*");
} else {
throw new RuntimeException("Found a reactant match for an orphan product, this should not be possible.");
}
}
}
// we try to match orphaned reactant mtp and product mtp of the same kind, as long neither list is empty
for (MolecularTypePattern mtpr : mtpReactantList) {
if (mtpProductList.isEmpty()) {
// nothing left to match
break;
}
MolecularTypePattern mtpp = mtpProductList.get(0);
if (mtpp != null) {
// these 2 are orphans and can be matched to each other
String matchKey = generateNewMatchKey(pairAlreadyMapped);
mtpr.setParticipantMatchLabel(matchKey);
mtpp.setParticipantMatchLabel(matchKey);
// mtpReactantList.remove(mtpr); // we can't remove them because of concurrent exception and actually we don't need to
mtpProductList.remove(mtpp);
pairAlreadyMapped.put(matchKey, mtpr);
}
}
}
}
use of org.vcell.model.rbm.MolecularType 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.MolecularType in project vcell by virtualcell.
the class Model method vetoableChange.
/**
* This method was created in VisualAge.
* @param e java.beans.PropertyChangeEvent
* @exception java.beans.PropertyVetoException The exception description.
*/
public void vetoableChange(PropertyChangeEvent e) throws ModelPropertyVetoException {
if (e.getSource() instanceof Structure) {
if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
if (getStructure((String) e.getNewValue()) != null) {
throw new ModelPropertyVetoException("another structure already using name " + e.getNewValue(), e);
}
}
}
if (e.getSource() instanceof ReactionStep) {
if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
String newName = (String) e.getNewValue();
if (getReactionStep(newName) != null) {
throw new ModelPropertyVetoException("another reaction step is already using name '" + newName + "'", e);
}
// validateNamingConflicts("Reaction",ReactionStep.class, newName, e);
}
}
if (e.getSource() instanceof ReactionRule && e.getPropertyName().equals(PropertyConstants.PROPERTY_NAME_NAME)) {
if (!e.getOldValue().equals(e.getNewValue())) {
String newName = (String) e.getNewValue();
if (getRbmModelContainer().getReactionRule(newName) != null) {
throw new ModelPropertyVetoException("another reaction rule is already using name '" + newName + "'", e);
}
validateNamingConflicts("Rule", ReactionRule.class, newName, e);
}
}
if (e.getSource() instanceof SpeciesContext) {
if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
String newName = (String) e.getNewValue();
SpeciesContext sc = getSpeciesContext(newName);
if (sc != null) {
throw new ModelPropertyVetoException("another " + SpeciesContext.getTerm() + " defined in '" + sc.getStructure().getName() + "' already uses name '" + e.getNewValue() + "'", e);
}
validateNamingConflicts("SpeciesContext", SpeciesContext.class, newName, e);
}
}
if (e.getSource() instanceof MembraneVoltage) {
if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
String newName = (String) e.getNewValue();
SymbolTableEntry existingSTE = getLocalEntry(newName);
if (existingSTE instanceof MembraneVoltage) {
throw new ModelPropertyVetoException("new name \"" + newName + "\" conflicts with the voltage parameter name for membrane \"" + ((MembraneVoltage) existingSTE).getMembrane().getName() + "\"", e);
}
validateNamingConflicts("MembraneVoltage", MembraneVoltage.class, newName, e);
}
}
if (e.getSource() instanceof StructureSize) {
if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
String newName = (String) e.getNewValue();
SymbolTableEntry existingSTE = getLocalEntry(newName);
if (existingSTE instanceof StructureSize) {
throw new ModelPropertyVetoException("new name \"" + newName + "\" conflicts with the size parameter name for structure \"" + ((StructureSize) existingSTE).getStructure().getName() + "\"", e);
}
validateNamingConflicts("StructureSize", StructureSize.class, newName, e);
}
}
if (e.getSource() instanceof ModelParameter) {
if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
String newName = (String) e.getNewValue();
if (getModelParameter(newName) != null) {
throw new ModelPropertyVetoException("Model Parameter with name '" + newName + "' already exists.", e);
}
validateNamingConflicts("Model Parameter", ModelParameter.class, newName, e);
}
}
if (e.getSource() instanceof MolecularType) {
if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
String newName = (String) e.getNewValue();
if (getRbmModelContainer().getMolecularType(newName) != null) {
throw new ModelPropertyVetoException(MolecularType.typeName + " with name '" + newName + "' already exists.", e);
}
validateNamingConflicts(((MolecularType) e.getSource()).getDisplayType(), MolecularType.class, newName, e);
}
}
if (e.getSource() instanceof RbmObservable) {
if (e.getPropertyName().equals("name") && !e.getOldValue().equals(e.getNewValue())) {
String newName = (String) e.getNewValue();
if (getRbmModelContainer().getObservable(newName) != null) {
throw new ModelPropertyVetoException(((RbmObservable) e.getSource()).getDisplayType() + " with name '" + newName + "' already exists.", e);
}
validateNamingConflicts(((RbmObservable) e.getSource()).getDisplayType(), RbmObservable.class, newName, e);
}
}
if (e.getSource() instanceof Species) {
if (e.getPropertyName().equals("commonName") && !e.getOldValue().equals(e.getNewValue())) {
String commonName = (String) e.getNewValue();
if (commonName == null) {
throw new ModelPropertyVetoException("species name cannot be null", e);
}
//
if (getSpecies(commonName) != null) {
throw new ModelPropertyVetoException("Species with common name '" + commonName + "' already defined", e);
}
if (getReservedSymbolByName(commonName) != null) {
throw new ModelPropertyVetoException("cannot use reserved symbol '" + commonName + "' as a Species common name", e, ModelPropertyVetoException.Category.RESERVED_SYMBOL);
}
}
}
if (e.getSource() == this && e.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_MOLECULAR_TYPE_LIST)) {
ArrayList<MolecularType> newMolecularTypes = (ArrayList<MolecularType>) e.getNewValue();
if (newMolecularTypes == null) {
throw new ModelPropertyVetoException(MolecularType.typeName + " list cannot be null", e);
}
for (MolecularType mt : getRbmModelContainer().getMolecularTypeList()) {
validateNamingConflicts(MolecularType.typeName, MolecularType.class, mt.getName(), e);
}
}
if (e.getSource() == this && e.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_OBSERVABLE_LIST)) {
ArrayList<RbmObservable> newObservables = (ArrayList<RbmObservable>) e.getNewValue();
if (newObservables == null) {
throw new ModelPropertyVetoException(RbmObservable.typeName + " list cannot be null", e);
}
for (RbmObservable observable : getRbmModelContainer().getObservableList()) {
validateNamingConflicts(RbmObservable.typeName, RbmObservable.class, observable.getName(), e);
}
}
if (e.getSource() == this && e.getPropertyName().equals(RbmModelContainer.PROPERTY_NAME_REACTION_RULE_LIST)) {
ArrayList<ReactionRule> newReactionRules = (ArrayList<ReactionRule>) e.getNewValue();
if (newReactionRules == null) {
throw new ModelPropertyVetoException(ReactionRule.typeName + " list cannot be null", e);
}
for (ReactionRule rr : getRbmModelContainer().getReactionRuleList()) {
validateNamingConflicts(ReactionRule.typeName, ReactionRule.class, rr.getName(), e);
}
}
if (e.getSource() == this && e.getPropertyName().equals(PROPERTY_NAME_STRUCTURES)) {
Structure[] newStructures = (Structure[]) e.getNewValue();
if (newStructures == null) {
throw new ModelPropertyVetoException("structures cannot be null", e);
}
//
// look for duplicates of structure name, structure size name, membrane voltage name within new "structures" array
// and look for symbol conflicts for StructureSize name and for MembraneVoltage name in existing "local" symbols.
//
HashSet<String> structNameSet = new HashSet<String>();
HashSet<String> structSymbolSet = new HashSet<String>();
for (int i = 0; i < newStructures.length; i++) {
String newStructureName = newStructures[i].getName();
if (structNameSet.contains(newStructureName)) {
throw new ModelPropertyVetoException("multiple structures with name '" + newStructureName + "' defined", e);
}
structNameSet.add(newStructureName);
if (newStructures[i] instanceof Membrane) {
String newMembraneVoltageName = ((Membrane) newStructures[i]).getMembraneVoltage().getName();
if (structSymbolSet.contains(newMembraneVoltageName)) {
// throw new ModelPropertyVetoException("membrane '"+newStructureName+"' has Voltage name '"+newMembraneVoltageName+"' that conflicts with another Voltage name or Size name",e);
}
structSymbolSet.add(newMembraneVoltageName);
validateNamingConflicts("MembraneVoltage", MembraneVoltage.class, newMembraneVoltageName, e);
}
String newStructureSizeName = newStructures[i].getStructureSize().getName();
if (structSymbolSet.contains(newStructureSizeName)) {
throw new ModelPropertyVetoException("structure '" + newStructureName + "' has structure Size name '" + newStructureSizeName + "' that conflicts with another Voltage name or Size name", e);
}
structSymbolSet.add(newStructureSizeName);
validateNamingConflicts("StructureSize", StructureSize.class, newStructureSizeName, e);
}
}
if (e.getSource() == this && e.getPropertyName().equals(PROPERTY_NAME_SPECIES)) {
Species[] newSpeciesArray = (Species[]) e.getNewValue();
if (newSpeciesArray == null) {
throw new ModelPropertyVetoException("species cannot be null", e);
}
//
// check that names are not duplicated and that no common names are ReservedSymbols
//
HashSet<String> commonNameSet = new HashSet<String>();
for (int i = 0; i < newSpeciesArray.length; i++) {
String commonName = newSpeciesArray[i].getCommonName();
if (commonNameSet.contains(commonName)) {
throw new ModelPropertyVetoException("multiple species with common name '" + commonName + "' defined", e);
}
if (getReservedSymbolByName(commonName) != null) {
throw new ModelPropertyVetoException("cannot use reserved symbol '" + commonName + "' as a Species common name", e, ModelPropertyVetoException.Category.RESERVED_SYMBOL);
}
commonNameSet.add(commonName);
}
//
for (int j = 0; j < fieldSpeciesContexts.length; j++) {
SpeciesContext sc = fieldSpeciesContexts[j];
boolean bFound = false;
for (int i = 0; i < newSpeciesArray.length; i++) {
if (newSpeciesArray[i] == sc.getSpecies()) {
bFound = true;
}
}
if (!bFound) {
throw new ModelPropertyVetoException("species[] missing '" + sc.getSpecies().getCommonName() + "' referenced in SpeciesContext '" + sc.getName() + "'", e);
}
}
}
if (e.getSource() == this && e.getPropertyName().equals(Model.PROPERTY_NAME_MODEL_PARAMETERS)) {
ModelParameter[] newModelParams = (ModelParameter[]) e.getNewValue();
//
// check that names are not duplicated and that no common names are ReservedSymbols
//
HashSet<String> namesSet = new HashSet<String>();
for (int i = 0; i < newModelParams.length; i++) {
if (namesSet.contains(newModelParams[i].getName())) {
throw new ModelPropertyVetoException("Multiple model/global parameters with same name '" + newModelParams[i].getName() + "' defined", e);
}
namesSet.add(newModelParams[i].getName());
validateNamingConflicts("Model Parameter", ModelParameter.class, newModelParams[i].getName(), e);
}
//
// make sure that kinetics of reactionSteps do not refer to modelParameter to be deleted
// Find this model parameter, missing from 'newModelParams'; loop thro' all reactionStep kinetics to determine if it is used
//
ModelParameter[] oldModelParameters = (ModelParameter[]) e.getOldValue();
if (oldModelParameters.length > newModelParams.length) {
// if 'newModelParameter' is smaller than 'oldModelParameter', one of the modelParams has been removed, find the missing one
ModelParameter missingMP = null;
for (int i = 0; i < oldModelParameters.length; i++) {
if (!BeanUtils.arrayContains(newModelParams, oldModelParameters[i])) {
missingMP = oldModelParameters[i];
}
}
// use this missing model parameter (to be deleted) to determine if it is used in any reaction kinetic parameters.
if (missingMP != null) {
Vector<String> referencingRxnsVector = new Vector<String>();
for (int i = 0; i < fieldReactionSteps.length; i++) {
KineticsParameter[] kParams = fieldReactionSteps[i].getKinetics().getKineticsParameters();
for (int k = 0; k < kParams.length; k++) {
if (kParams[k].getExpression().hasSymbol(missingMP.getName()) && (fieldReactionSteps[i].getKinetics().getProxyParameter(missingMP.getName()) != null)) {
referencingRxnsVector.add(fieldReactionSteps[i].getName());
break;
}
}
}
// if there are any reactionSteps referencing the global, list them all in error msg.
if (referencingRxnsVector.size() > 0) {
String msg = "Model Parameter '" + missingMP.getName() + "' is used in reaction(s): ";
for (int i = 0; i < referencingRxnsVector.size(); i++) {
msg = msg + "'" + referencingRxnsVector.elementAt(i) + "'";
if (i < referencingRxnsVector.size() - 1) {
msg = msg + ", ";
} else {
msg = msg + ". ";
}
}
msg = msg + "\n\nCannot delete '" + missingMP.getName() + "'.";
throw new ModelPropertyVetoException(msg, e);
}
// At this point, it is not referenced in a reactionStep, find out if the missing model is used in other model parameters
// Enough to check in newModelParams array
Vector<String> referencingModelParamsVector = new Vector<String>();
for (int i = 0; i < newModelParams.length; i++) {
if (newModelParams[i].getExpression().hasSymbol(missingMP.getName())) {
referencingModelParamsVector.add(newModelParams[i].getName());
}
}
// if there are any model parameters referencing the global, list them all in error msg.
if (referencingModelParamsVector.size() > 0) {
String msg = "Model Parameter '" + missingMP.getName() + "' is used in expression of other model parameter(s): ";
for (int i = 0; i < referencingModelParamsVector.size(); i++) {
msg = msg + "'" + referencingModelParamsVector.elementAt(i) + "'";
if (i < referencingModelParamsVector.size() - 1) {
msg = msg + ", ";
} else {
msg = msg + ". ";
}
}
msg = msg + "\n\nCannot delete '" + missingMP.getName() + "'.";
throw new ModelPropertyVetoException(msg, e);
}
}
}
}
if (e.getSource() == this && e.getPropertyName().equals(PROPERTY_NAME_SPECIES_CONTEXTS)) {
SpeciesContext[] newSpeciesContextArray = (SpeciesContext[]) e.getNewValue();
if (newSpeciesContextArray == null) {
throw new ModelPropertyVetoException("speciesContexts cannot be null", e);
}
//
for (int i = 0; i < newSpeciesContextArray.length; i++) {
if (!contains(newSpeciesContextArray[i].getSpecies())) {
throw new ModelPropertyVetoException("can't add speciesContext '" + newSpeciesContextArray[i].getName() + "' before species '" + newSpeciesContextArray[i].getSpecies().getCommonName() + "'", e);
}
if (!contains(newSpeciesContextArray[i].getStructure())) {
throw new ModelPropertyVetoException("can't add speciesContext '" + newSpeciesContextArray[i].getName() + "' before structure '" + newSpeciesContextArray[i].getStructure().getName() + "'", e);
}
}
//
// check that names are not duplicated and that no names are ReservedSymbols
//
HashSet<String> nameSet = new HashSet<String>();
for (int i = 0; i < newSpeciesContextArray.length; i++) {
if (nameSet.contains(newSpeciesContextArray[i].getName())) {
throw new ModelPropertyVetoException("multiple speciesContexts with name '" + newSpeciesContextArray[i].getName() + "' defined", e);
}
nameSet.add(newSpeciesContextArray[i].getName());
validateNamingConflicts("SpeciesContext", newSpeciesContextArray[i].getClass(), newSpeciesContextArray[i].getName(), e);
}
//
for (int i = 0; i < fieldReactionSteps.length; i++) {
ReactionParticipant[] rpArray = fieldReactionSteps[i].getReactionParticipants();
for (int k = 0; k < rpArray.length; k++) {
boolean bFound = false;
for (int j = 0; j < newSpeciesContextArray.length; j++) {
if (newSpeciesContextArray[j] == rpArray[k].getSpeciesContext()) {
bFound = true;
break;
}
}
if (!bFound) {
throw new ModelPropertyVetoException("reaction '" + fieldReactionSteps[i].getName() + "' requires '" + rpArray[k].getSpeciesContext().getName() + "'", e);
}
}
}
}
if (e.getSource() == this && e.getPropertyName().equals(PROPERTY_NAME_REACTION_STEPS)) {
ReactionStep[] newReactionStepArr = (ReactionStep[]) e.getNewValue();
//
for (int i = 0; i < newReactionStepArr.length; i += 1) {
if (newReactionStepArr[i] == null) {
throw new ModelPropertyVetoException("Null cannot be added to ReactionStep", e);
}
}
//
// check that names are not duplicated and that no names are ReservedSymbols
// because math generator complained if reactionsteps had same name
//
HashSet<String> nameSet = new HashSet<String>();
for (int i = 0; i < newReactionStepArr.length; i++) {
String rxnName = newReactionStepArr[i].getName();
if (nameSet.contains(rxnName)) {
throw new ModelPropertyVetoException("multiple reactionSteps with name '" + rxnName + "' defined", e);
}
if (getReservedSymbolByName(rxnName) != null) {
throw new ModelPropertyVetoException("cannot use reserved symbol '" + rxnName + "' as a Reaction name", e, ModelPropertyVetoException.Category.RESERVED_SYMBOL);
}
nameSet.add(rxnName);
// validateNamingConflicts("Reaction", ReactionStep.class, newReactionStepArr[i].getName(), e);
}
//
for (int i = 0; i < newReactionStepArr.length; i++) {
ReactionParticipant[] rpArray = newReactionStepArr[i].getReactionParticipants();
for (int k = 0; k < rpArray.length; k++) {
boolean bFound = false;
for (int j = 0; j < fieldSpeciesContexts.length; j++) {
if (fieldSpeciesContexts[j] == rpArray[k].getSpeciesContext()) {
bFound = true;
break;
}
}
if (!bFound) {
throw new ModelPropertyVetoException("reaction '" + newReactionStepArr[i].getName() + "' requires '" + rpArray[k].getSpeciesContext().getName() + "'", e);
}
}
}
}
}
use of org.vcell.model.rbm.MolecularType in project vcell by virtualcell.
the class Model method propertyChange.
/**
* This method gets called when a bound property is changed.
* @param evt A PropertyChangeEvent object describing the event source
* and the property that has changed.
*/
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (evt.getSource() instanceof ReactionStep && evt.getPropertyName().equals("kinetics")) {
Kinetics oldKinetics = (Kinetics) evt.getOldValue();
Kinetics newKinetics = (Kinetics) evt.getNewValue();
if (oldKinetics != null) {
oldKinetics.removePropertyChangeListener(this);
oldKinetics.removeVetoableChangeListener(this);
}
if (newKinetics != null) {
newKinetics.addPropertyChangeListener(this);
newKinetics.addVetoableChangeListener(this);
}
}
if (evt.getSource() instanceof SpeciesContext && evt.getPropertyName().equals("name")) {
for (int i = 0; i < fieldDiagrams.length; i++) {
fieldDiagrams[i].renameNode((String) evt.getOldValue(), (String) evt.getNewValue());
}
}
if (evt.getSource() instanceof ReactionStep && evt.getPropertyName().equals("name")) {
for (int i = 0; i < fieldDiagrams.length; i++) {
fieldDiagrams[i].renameNode((String) evt.getOldValue(), (String) evt.getNewValue());
}
}
// if we can't find any candidate or we find too many candidates we wisely (and silently) do nothing
if (evt.getSource() instanceof MolecularType && evt.getPropertyName().equals("name")) {
List<RbmObservable> candidates = new ArrayList<RbmObservable>();
String oldName = (String) evt.getOldValue();
String newName = (String) evt.getNewValue();
for (RbmObservable candidate : getRbmModelContainer().getObservableList()) {
if (candidate.getName().contains(oldName) && candidate.getName().startsWith("O") && candidate.getName().endsWith("_tot")) {
candidates.add(candidate);
}
}
if (candidates.isEmpty()) {
System.out.println("no candidates to rename");
} else if (candidates.size() > 1) {
System.out.println("too many candidates to rename");
} else {
RbmObservable candidate = candidates.get(0);
System.out.println("renaming --- " + candidate.getName());
try {
String prefix = candidate.getName().substring(0, candidate.getName().indexOf("_"));
candidate.setName(prefix + "_" + newName + "_tot");
} catch (PropertyVetoException e) {
System.out.println("Cannot rename observable " + candidate.getName() + ", " + e.getMessage());
e.printStackTrace();
}
}
}
//
if ((evt.getSource() instanceof ModelParameter || evt.getSource() instanceof SpeciesContext || evt.getSource() instanceof RbmObservable || evt.getSource() instanceof MembraneVoltage || evt.getSource() instanceof StructureSize) && evt.getPropertyName().equals("name")) {
for (int i = 0; i < fieldModelParameters.length; i++) {
try {
Expression exp = fieldModelParameters[i].getExpression();
Expression renamedExp = exp.renameBoundSymbols(getNameScope());
if (!renamedExp.compareEqual(exp)) {
fieldModelParameters[i].setExpression(renamedExp);
}
} catch (ExpressionBindingException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
}
}
}
Aggregations