use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class BioModelEditorModelPanel method newMemButtonPressed.
private void newMemButtonPressed() {
computeCurrentSelectedTable();
Object newObject = null;
if (currentSelectedTable == structuresTable) {
try {
Membrane membrane = bioModel.getModel().createMembrane();
newObject = membrane;
} catch (Exception e) {
e.printStackTrace();
DialogUtils.showErrorDialog(this, e.getMessage(), e);
}
}
if (newObject != null) {
for (int i = 0; i < currentSelectedTableModel.getRowCount(); i++) {
if (currentSelectedTableModel.getValueAt(i) == newObject) {
currentSelectedTable.setRowSelectionInterval(i, i);
break;
}
}
}
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class XmlReader method getKinetics.
/**
* This method returns a Kinetics object from a XML Element based on the value of the kinetics type attribute.
* Creation date: (3/19/2001 4:42:04 PM)
* @return cbit.vcell.model.Kinetics
* @param param org.jdom.Element
*/
private Kinetics getKinetics(Element param, ReactionStep reaction, Model model) throws XmlParseException {
VariableHash varHash = new VariableHash();
addResevedSymbols(varHash, model);
String type = param.getAttributeValue(XMLTags.KineticsTypeAttrTag);
Kinetics newKinetics = null;
try {
if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralKinetics)) {
// create a general kinetics
newKinetics = new GeneralKinetics(reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralCurrentKinetics)) {
// Create GeneralCurrentKinetics
newKinetics = new GeneralCurrentKinetics(reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeMassAction) && reaction instanceof SimpleReaction) {
// create a Mass Action kinetics
newKinetics = new MassActionKinetics((SimpleReaction) reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeNernst) && reaction instanceof FluxReaction) {
// create NernstKinetics
newKinetics = new NernstKinetics((FluxReaction) reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGHK) && reaction instanceof FluxReaction) {
// create GHKKinetics
newKinetics = new GHKKinetics((FluxReaction) reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeHMM_Irr) && reaction instanceof SimpleReaction) {
// create HMM_IrrKinetics
newKinetics = new HMM_IRRKinetics((SimpleReaction) reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeHMM_Rev) && reaction instanceof SimpleReaction) {
// create HMM_RevKinetics
newKinetics = new HMM_REVKinetics((SimpleReaction) reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralTotal_oldname)) {
// create GeneralTotalKinetics
newKinetics = new GeneralLumpedKinetics(reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralLumped)) {
// create GeneralLumpedKinetics
newKinetics = new GeneralLumpedKinetics(reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralCurrentLumped)) {
// create GeneralCurrentLumpedKinetics
newKinetics = new GeneralCurrentLumpedKinetics(reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeGeneralPermeability) && reaction instanceof FluxReaction) {
// create GeneralPermeabilityKinetics
newKinetics = new GeneralPermeabilityKinetics((FluxReaction) reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeMacroscopic_Irr) && reaction instanceof SimpleReaction) {
// create Macroscopic_IRRKinetics
newKinetics = new Macroscopic_IRRKinetics((SimpleReaction) reaction);
} else if (type.equalsIgnoreCase(XMLTags.KineticsTypeMicroscopic_Irr) && reaction instanceof SimpleReaction) {
// create Microscopic_IRRKinetics
newKinetics = new Microscopic_IRRKinetics((SimpleReaction) reaction);
} else {
throw new XmlParseException("Unknown kinetics type: " + type);
}
} catch (ExpressionException e) {
e.printStackTrace();
throw new XmlParseException("Error creating the kinetics for reaction: " + reaction.getName(), e);
}
try {
// transaction begin flag ... yeah, this is a hack
newKinetics.reading(true);
// Read all of the parameters
List<Element> list = param.getChildren(XMLTags.ParameterTag, vcNamespace);
// add constants that may be used in kinetics.
// VariableHash varHash = getVariablesHash();
ArrayList<String> reserved = new ArrayList<String>();
ReservedSymbol[] reservedSymbols = reaction.getModel().getReservedSymbols();
for (ReservedSymbol rs : reservedSymbols) {
reserved.add(rs.getName());
}
try {
if (reaction.getStructure() instanceof Membrane) {
Membrane membrane = (Membrane) reaction.getStructure();
varHash.addVariable(new Constant(membrane.getMembraneVoltage().getName(), new Expression(0.0)));
reserved.add(membrane.getMembraneVoltage().getName());
}
//
// add Reactants, Products, and Catalysts (ReactionParticipants)
//
ReactionParticipant[] rp = reaction.getReactionParticipants();
for (int i = 0; i < rp.length; i++) {
varHash.addVariable(new Constant(rp[i].getName(), new Expression(0.0)));
}
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException("error reordering parameters according to dependencies: ", e);
}
//
for (Element xmlParam : list) {
String paramName = unMangle(xmlParam.getAttributeValue(XMLTags.NameAttrTag));
String role = xmlParam.getAttributeValue(XMLTags.ParamRoleAttrTag);
String paramExpStr = xmlParam.getText();
Expression paramExp = unMangleExpression(paramExpStr);
try {
if (varHash.getVariable(paramName) == null) {
varHash.addVariable(new Function(paramName, paramExp, null));
} else {
if (reserved.contains(paramName)) {
varHash.removeVariable(paramName);
varHash.addVariable(new Function(paramName, paramExp, null));
}
}
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException("error reordering parameters according to dependencies: ", e);
}
Kinetics.KineticsParameter tempParam = null;
if (!role.equals(XMLTags.ParamRoleUserDefinedTag)) {
tempParam = newKinetics.getKineticsParameterFromRole(Kinetics.getParamRoleFromDefaultDesc(role));
} else {
continue;
}
// hack for bringing in General Total kinetics without breaking.
if (tempParam == null && newKinetics instanceof GeneralLumpedKinetics) {
if (role.equals(Kinetics.GTK_AssumedCompartmentSize_oldname) || role.equals(Kinetics.GTK_ReactionRate_oldname) || role.equals(Kinetics.GTK_CurrentDensity_oldname)) {
continue;
} else if (role.equals(VCMODL.TotalRate_oldname)) {
tempParam = newKinetics.getKineticsParameterFromRole(Kinetics.ROLE_LumpedReactionRate);
}
}
// hack from bringing in chargeValence parameters without breaking
if (tempParam == null && Kinetics.getParamRoleFromDefaultDesc(role) == Kinetics.ROLE_ChargeValence) {
tempParam = newKinetics.getChargeValenceParameter();
}
if (tempParam == null) {
throw new XmlParseException("parameter with role '" + role + "' not found in kinetics type '" + type + "'");
}
//
if (!tempParam.getName().equals(paramName)) {
Kinetics.KineticsParameter multNameParam = newKinetics.getKineticsParameter(paramName);
int n = 0;
while (multNameParam != null) {
String tempName = paramName + "_" + n++;
newKinetics.renameParameter(paramName, tempName);
multNameParam = newKinetics.getKineticsParameter(tempName);
}
newKinetics.renameParameter(tempParam.getName(), paramName);
}
}
//
// create unresolved parameters for all unresolved symbols
//
String unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
while (unresolvedSymbol != null) {
try {
// will turn into an UnresolvedParameter.
varHash.addVariable(new Function(unresolvedSymbol, new Expression(0.0), null));
} catch (MathException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
newKinetics.addUnresolvedParameter(unresolvedSymbol);
unresolvedSymbol = varHash.getFirstUnresolvedSymbol();
}
Variable[] sortedVariables = varHash.getTopologicallyReorderedVariables();
ModelUnitSystem modelUnitSystem = reaction.getModel().getUnitSystem();
for (int i = sortedVariables.length - 1; i >= 0; i--) {
if (sortedVariables[i] instanceof Function) {
Function paramFunction = (Function) sortedVariables[i];
Element xmlParam = null;
for (int j = 0; j < list.size(); j++) {
Element tempParam = (Element) list.get(j);
if (paramFunction.getName().equals(unMangle(tempParam.getAttributeValue(XMLTags.NameAttrTag)))) {
xmlParam = tempParam;
break;
}
}
if (xmlParam == null) {
// must have been an unresolved parameter
continue;
}
String symbol = xmlParam.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
VCUnitDefinition unit = null;
if (symbol != null) {
unit = modelUnitSystem.getInstance(symbol);
}
Kinetics.KineticsParameter tempParam = newKinetics.getKineticsParameter(paramFunction.getName());
if (tempParam == null) {
newKinetics.addUserDefinedKineticsParameter(paramFunction.getName(), paramFunction.getExpression(), unit);
} else {
newKinetics.setParameterValue(tempParam, paramFunction.getExpression());
tempParam.setUnitDefinition(unit);
}
}
}
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new XmlParseException("Exception while setting parameters for Reaction : " + reaction.getName(), e);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException("Exception while settings parameters for Reaction : " + reaction.getName(), e);
} finally {
newKinetics.reading(false);
}
return newKinetics;
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class RbmNetworkGenerator method writeCompartments.
// ======================================================================================================
public static void writeCompartments(PrintWriter writer, Model model, SimulationContext sc) {
writer.println(BEGIN_COMPARTMENTS);
for (int i = 0; i < model.getStructures().length; i++) {
Structure s = model.getStructure(i);
String name = s.getName();
int dim;
if (s instanceof Membrane) {
dim = 2;
} else {
dim = 3;
}
// double volume = 0.0;
// StructureMapping sm = sc.getGeometryContext().getStructureMapping(s);
// try{
// Expression sizeExpr = sm.getSizeParameter().getExpression();
// volume = sizeExpr.evaluateConstant();
// } catch(ExpressionException e){
// e.printStackTrace(System.out);
// }
//
// compartment size is always 1 when we export internally to bngl
// because we adjust within vCell the kinetic parameters and whatnot so that everything is scaled by size
//
writer.println(name + "\t" + dim + "\t" + 1);
}
writer.println(END_COMPARTMENTS);
writer.println();
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class XmlReader method getMembraneMapping.
/**
* This method retuns a MembraneMapping object from a XML representation.
* Creation date: (5/7/2001 4:12:03 PM)
* @return cbit.vcell.mapping.MembraneMapping
* @param param org.jdom.Element
*/
private MembraneMapping getMembraneMapping(Element param, SimulationContext simulationContext) throws XmlParseException {
// Retrieve attributes
String membranename = unMangle(param.getAttributeValue(XMLTags.MembraneAttrTag));
Membrane membraneref = (Membrane) simulationContext.getModel().getStructure(membranename);
if (membraneref == null) {
throw new XmlParseException("The Membrane " + membranename + " could not be resolved!");
}
// *** Create new Membrane Mapping ****
MembraneMapping memmap = new MembraneMapping(membraneref, simulationContext, simulationContext.getModel().getUnitSystem());
// Set SurfacetoVolumeRatio when it exists, amended Sept. 27th, 2007
if (param.getAttributeValue(XMLTags.SurfaceToVolumeRatioTag) != null) {
String ratio = unMangle(param.getAttributeValue(XMLTags.SurfaceToVolumeRatioTag));
try {
memmap.getSurfaceToVolumeParameter().setExpression(unMangleExpression(ratio));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException("An expressionException was fired when setting the SurfacetoVolumeRatio Expression " + ratio + " to a membraneMapping!", e);
}
}
// Set VolumeFraction when it exists, amended Sept. 27th, 2007
if (param.getAttributeValue(XMLTags.VolumeFractionTag) != null) {
String fraction = unMangle(param.getAttributeValue(XMLTags.VolumeFractionTag));
try {
memmap.getVolumeFractionParameter().setExpression(unMangleExpression(fraction));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException("An expressionException was fired when setting the VolumeFraction Expression " + fraction + " to a membraneMapping!", e);
}
}
// Set Area/unit_area if it exists, amended Sept. 27th, 2007
if (param.getAttributeValue(XMLTags.AreaPerUnitAreaTag) != null) {
String ratio = unMangle(param.getAttributeValue(XMLTags.AreaPerUnitAreaTag));
try {
memmap.getAreaPerUnitAreaParameter().setExpression(unMangleExpression(ratio));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException("An expressionException was fired when setting the AreaPerUnitArea Expression " + ratio + " to a membraneMapping!", e);
}
}
// Set SurfacetoVolumeRatio when it exists, amended Sept. 27th, 2007
if (param.getAttributeValue(XMLTags.AreaPerUnitVolumeTag) != null) {
String ratio = unMangle(param.getAttributeValue(XMLTags.AreaPerUnitVolumeTag));
try {
memmap.getAreaPerUnitVolumeParameter().setExpression(unMangleExpression(ratio));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException("An expressionException was fired when setting the AreaPerUnitVolume Expression " + ratio + " to a membraneMapping!", e);
}
}
// Set Size
if (param.getAttributeValue(XMLTags.SizeTag) != null) {
String size = unMangle(param.getAttributeValue(XMLTags.SizeTag));
try {
memmap.getSizeParameter().setExpression(unMangleExpression(size));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException("An expressionException was fired when setting the size Expression " + size + " to a membraneMapping!", e);
}
} else {
try {
memmap.getSizeParameter().setExpression(null);
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("unexpected exception while setting structure size", e);
}
}
// ** Set electrical properties **
// set specific capacitance
double specificCap = Double.parseDouble(param.getAttributeValue(XMLTags.SpecificCapacitanceTag));
try {
memmap.getSpecificCapacitanceParameter().setExpression(new Expression(specificCap));
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
// set flag calculate voltage
boolean calculateVolt = (Boolean.valueOf(param.getAttributeValue(XMLTags.CalculateVoltageTag))).booleanValue();
memmap.setCalculateVoltage(calculateVolt);
// set initial Voltage
String initialVoltString = param.getAttributeValue(XMLTags.InitialVoltageTag);
try {
Expression initialExpr = unMangleExpression(initialVoltString);
memmap.getInitialVoltageParameter().setExpression(initialExpr);
} catch (ExpressionException e) {
e.printStackTrace(System.out);
throw new XmlParseException(e);
}
String geometryClassName = param.getAttributeValue(XMLTags.GeometryClassAttrTag);
if (geometryClassName != null) {
geometryClassName = unMangle(geometryClassName);
}
// Retrieve subvolumeref, allow subvolumes to be 'null'
if (geometryClassName != null) {
GeometryClass[] geometryClasses = simulationContext.getGeometry().getGeometryClasses();
for (int i = 0; i < geometryClasses.length; i++) {
if (geometryClasses[i].getName().equals(geometryClassName)) {
try {
memmap.setGeometryClass(geometryClasses[i]);
} catch (PropertyVetoException e) {
e.printStackTrace();
throw new XmlParseException("A propertyVetoException was fired when trying to set the subvolume or surface " + geometryClassName + " to a MembraneMapping!", e);
}
}
}
}
return memmap;
}
use of cbit.vcell.model.Membrane in project vcell by virtualcell.
the class StructurePropertiesPanel method getExplanationText.
private String getExplanationText() {
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
String voltageName = membrane.getMembraneVoltage().getName();
Feature posFeature = fieldModel.getElectricalTopology().getPositiveFeature(membrane);
Feature negFeature = fieldModel.getElectricalTopology().getNegativeFeature(membrane);
String posCompName = (posFeature != null) ? posFeature.getName() : "inside (+) compartment";
String negCompName = (negFeature != null) ? negFeature.getName() : "outside (-) compartment";
return "<html><b>membrane voltage</i>:</b> <font color=\"blue\">\"" + voltageName + "\"</font> = voltage(<font color=\"blue\">" + posCompName + "</font>) - voltage(<font color=\"blue\">" + negCompName + "</font>)</i><br/>" + "<b>inward currents:</b> from compartment <font color=\"blue\">\"" + negCompName + "\"</font> into compartment <font color=\"blue\">\"" + posCompName + "\"</font>" + "<font color=\"red\"><i><br/>Note: VCell reactions and fluxes specify inward currents (- to +) rather than conventional currents (+ to -).</i></font>" + "</html>";
} else {
return "";
}
}
Aggregations