use of cbit.vcell.math.ParticleComponentStateDefinition in project vcell by virtualcell.
the class XmlReader method getParticleMolecularComponentPattern.
private ParticleMolecularComponentPattern getParticleMolecularComponentPattern(Element param, ParticleMolecularType particleMolecularType) throws XmlParseException {
String molecularComponentName = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
ParticleMolecularComponent particleMolecularComponent = particleMolecularType.getMolecularComponent(molecularComponentName);
if (particleMolecularComponent != null) {
ParticleMolecularComponentPattern var = new ParticleMolecularComponentPattern(particleMolecularComponent);
ParticleComponentStatePattern pcsp = null;
String componentStateName = unMangle(param.getAttributeValue(XMLTags.StateAttrTag));
if (componentStateName.equals("*")) {
pcsp = new ParticleComponentStatePattern();
} else {
// ParticleComponentStateDefinition pcsd = new ParticleComponentStateDefinition(componentStateName); // bad??
ParticleComponentStateDefinition pcsd = particleMolecularComponent.getComponentStateDefinition(componentStateName);
if (pcsd == null) {
throw new XmlParseException("failed to find ParticleComponentStateDefinition named " + molecularComponentName);
}
pcsp = new ParticleComponentStatePattern(pcsd);
}
var.setComponentStatePattern(pcsp);
String bondString = unMangle(param.getAttributeValue(XMLTags.BondAttrTag));
ParticleBondType bondType = ParticleBondType.fromSymbol(bondString);
if (bondType == ParticleBondType.Specified) {
int bondId = Integer.parseInt(bondString);
var.setBondId(bondId);
}
var.setBondType(bondType);
return var;
} else {
throw new XmlParseException("failed to find ParticleMolecularComponent named " + molecularComponentName);
}
}
use of cbit.vcell.math.ParticleComponentStateDefinition in project vcell by virtualcell.
the class NFsimXMLWriter method getListOfAllowedStates.
private static Element getListOfAllowedStates(ParticleMolecularComponent molecularComponent) {
if (molecularComponent.getComponentStateDefinitions().isEmpty()) {
return null;
}
Element listOfAllowedStates = new Element("ListOfAllowedStates");
for (ParticleComponentStateDefinition componentStateDefinition : molecularComponent.getComponentStateDefinitions()) {
Element allowedStateElement = new Element("AllowedState");
allowedStateElement.setAttribute("id", componentStateDefinition.getName());
listOfAllowedStates.addContent(allowedStateElement);
}
return listOfAllowedStates;
}
use of cbit.vcell.math.ParticleComponentStateDefinition in project vcell by virtualcell.
the class NFsimXMLWriter method getListOfComponents1.
private static Element getListOfComponents1(String reactionRuleID, String patternID, String moleculeID, ParticleSpeciesPattern speciesPattern, ParticleMolecularTypePattern particleMolecularTypePattern, ArrayList<ComponentOfMolecularTypeOfReactionParticipant> currentComponentOfParticipant, HashMap<Bond, BondSites> bondSitesMap) throws SolverException {
// while traversing Components of a MolecularTypePattern, it populates bondSiteMapping
Element listOfComponentsElement = new Element("ListOfComponents");
for (int componentId = 0; componentId < particleMolecularTypePattern.getMolecularComponentPatternList().size(); componentId++) {
ParticleMolecularComponentPattern particleMolecularComponentPattern = particleMolecularTypePattern.getMolecularComponentPatternList().get(componentId);
Element componentElement = new Element("Component");
ParticleMolecularComponent particleMolecularComponent = particleMolecularComponentPattern.getMolecularComponent();
// componentElement.setAttribute("id", particleMolecularComponent.getId());
String elementID = "C" + (componentId + 1);
String componentID = reactionRuleID + "_" + patternID + "_" + moleculeID + "_" + elementID;
componentElement.setAttribute("id", componentID);
componentElement.setAttribute("name", particleMolecularComponent.getName());
ParticleComponentStatePattern componentStatePattern = particleMolecularComponentPattern.getComponentStatePattern();
ParticleComponentStateDefinition pcsd = componentStatePattern.getParticleComponentStateDefinition();
String state = "";
boolean ignoreFlagState = false;
if (componentStatePattern.isAny()) {
state = "*";
ignoreFlagState = true;
} else if (pcsd != null) {
state = pcsd.getName();
componentElement.setAttribute("state", state);
} else {
throw new RuntimeException("Invalid state for ParticleComponentStatePattern.");
}
// ParticleComponentState componentState = particleMolecularComponentPattern.getComponentState();
// String state = "";
// if (componentState!=null){
// state = componentState.getName();
// if(!state.equals("*")) {
// componentElement.setAttribute("state", state);
// }
// }
ComponentOfMolecularTypeOfReactionParticipant cper = new ComponentOfMolecularTypeOfReactionParticipant(particleMolecularTypePattern.getMolecularType().getName(), particleMolecularTypePattern.getMatchLabel(), particleMolecularComponent.getName(), componentID, state);
// number of bonds is 0 or 1 for species (concrete species). the bonds are listed later in the list of bonds
ParticleBondType bondType = particleMolecularComponentPattern.getBondType();
boolean ignoreFlagBond = false;
switch(bondType) {
case Exists:
{
componentElement.setAttribute("numberOfBonds", bondType.symbol);
break;
}
case None:
{
componentElement.setAttribute("numberOfBonds", "0");
break;
}
case Possible:
{
componentElement.setAttribute("numberOfBonds", bondType.symbol);
ignoreFlagBond = true;
break;
}
case Specified:
{
if (particleMolecularComponentPattern.getBondId() >= 0) {
componentElement.setAttribute("numberOfBonds", "1");
String bondID = reactionRuleID + "_" + patternID + "_B" + particleMolecularComponentPattern.getBondId();
Bond bond = new Bond(bondID, speciesPattern);
BondSites bondSites = bondSitesMap.get(bond);
if (bondSites == null) {
BondSites newBondSite = new BondSites();
newBondSite.component1 = componentID;
bondSitesMap.put(bond, newBondSite);
} else {
if (bondSites.component1.equals(componentID) || bondSites.component2.equals(componentID)) {
throw new SolverException("this molecularComponentPattern already set in bondSites");
}
if (bondSites.component2.equals("")) {
bondSites.component2 = componentID;
} else {
throw new SolverException("two other molecularComponentPatterns already set in bondSites");
}
}
} else {
componentElement.setAttribute("numberOfBonds", "0");
}
break;
}
}
if (ignoreFlagState == false || ignoreFlagBond == false) {
currentComponentOfParticipant.add(cper);
listOfComponentsElement.addContent(componentElement);
}
}
return listOfComponentsElement;
}
Aggregations