Skip to content

Commit

Permalink
WIP: CSG round trip to SBML
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed Sep 28, 2022
1 parent 35dcf1b commit c452790
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 34 deletions.
15 changes: 14 additions & 1 deletion vcell-core/src/main/java/cbit/vcell/geometry/CSGObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
package cbit.vcell.geometry;

import org.vcell.util.Compare;
import org.vcell.util.Extent;
import org.vcell.util.Matchable;
import org.vcell.util.Origin;
import org.vcell.util.document.KeyValue;

import cbit.image.ImageException;
Expand All @@ -33,7 +35,18 @@ public CSGObject(CSGObject csgObj) {
root = csgObj.root.clone();
}

public boolean compareEqual(Matchable obj) {
public static CSGObject createBackgroundObject(Origin vcOrigin, Extent vcExtent, String name, int handle) {
CSGPrimitive cube = new CSGPrimitive("background", CSGPrimitive.PrimitiveType.CUBE);
CSGScale scale = new CSGScale("scale",new Vect3d(2*vcExtent.getX(),2*vcExtent.getY(), 2*vcExtent.getZ()));
CSGTranslation translation = new CSGTranslation("translate", new Vect3d(-vcOrigin.getX(), -vcOrigin.getY(), -vcOrigin.getZ()));
scale.setChild(translation);
translation.setChild(cube);
CSGObject csgObject = new CSGObject(null ,name, handle);
csgObject.setRoot(scale);
return csgObject;
}

public boolean compareEqual(Matchable obj) {
if (!compareEqual0(obj)){
return false;
}
Expand Down
38 changes: 25 additions & 13 deletions vcell-core/src/main/java/org/vcell/sbml/vcell/SBMLExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -2085,7 +2085,8 @@ private void addGeometry() throws SbmlException {
if (vcGeomClasses[i] instanceof AnalyticSubVolume) {
AnalyticSubVolume vcAnalyticSubVolume = (AnalyticSubVolume) vcGeomClasses[i];
// need to avoid id name clash with structures (compartments)
AnalyticVolume analyticVol = sbmlAnalyticGeomDefinition.createAnalyticVolume(TokenMangler.mangleToSName("AnalyticVol_"+vcAnalyticSubVolume.getName()));
String id = TokenMangler.mangleToSName("AnalyticVol_" + vcAnalyticSubVolume.getName());
AnalyticVolume analyticVol = sbmlAnalyticGeomDefinition.createAnalyticVolume(id);
// analyticVol.setSpatialId(vcGeomClasses[i].getName());
analyticVol.setDomainType(DOMAIN_TYPE_PREFIX+vcAnalyticSubVolume.getName());
analyticVol.setFunctionType(FunctionKind.layered);
Expand All @@ -2107,19 +2108,30 @@ private void addGeometry() throws SbmlException {
//
// add CSGeometry
//
if (!bAnyAnalyticSubvolumes && !bAnyImageSubvolumes && bAnyCSGSubvolumes){
CSGeometry sbmlCSGeomDefinition = new CSGeometry();
sbmlGeometry.addGeometryDefinition(sbmlCSGeomDefinition);
// if (!bAnyAnalyticSubvolumes && !bAnyImageSubvolumes && bAnyCSGSubvolumes){
if (!bAnyImageSubvolumes && bAnyCSGSubvolumes){
CSGeometry sbmlCSGeomDefinition = sbmlGeometry.createCSGeometry();
sbmlCSGeomDefinition.setSpatialId(TokenMangler.mangleToSName("CSG_"+vcGeometry.getName()));
sbmlCSGeomDefinition.setIsActive(true);
for (int i = 0; i < vcGeomClasses.length; i++) {
if (vcGeomClasses[i] instanceof CSGObject) {
CSGObject vcellCSGObject = (CSGObject)vcGeomClasses[i];
org.sbml.jsbml.ext.spatial.CSGObject sbmlCSGObject = new org.sbml.jsbml.ext.spatial.CSGObject();
sbmlCSGeomDefinition.addCSGObject(sbmlCSGObject);
sbmlCSGObject.setSpatialId(vcellCSGObject.getName());
String id = TokenMangler.mangleToSName("CSGObject_" + vcellCSGObject.getName());
org.sbml.jsbml.ext.spatial.CSGObject sbmlCSGObject = sbmlCSGeomDefinition.createCSGObject(id);
sbmlCSGObject.setDomainType(DOMAIN_TYPE_PREFIX+vcellCSGObject.getName());
sbmlCSGObject.setOrdinal(numSubVols - (i+1)); // the ordinal should the the least for the default/background subVolume
sbmlCSGObject.setOrdinal(vcellCSGObject.getHandle()); // numSubVols - (i+1)); // the ordinal should be the least for the default/background subVolume
org.sbml.jsbml.ext.spatial.CSGNode sbmlcsgNode = getSBMLCSGNode(vcellCSGObject.getRoot());
sbmlcsgNode.setParent(sbmlCSGObject);
sbmlCSGObject.setCSGNode(sbmlcsgNode);
}else if (vcGeomClasses[i] instanceof AnalyticSubVolume && ((AnalyticSubVolume)vcGeomClasses[i]).getExpression().isOne()) {
AnalyticSubVolume analyticSubVolume = (AnalyticSubVolume)vcGeomClasses[i];
String id = TokenMangler.mangleToSName("CSGObject_" + analyticSubVolume.getName());
org.sbml.jsbml.ext.spatial.CSGObject sbmlCSGObject = sbmlCSGeomDefinition.createCSGObject(id);
sbmlCSGObject.setDomainType(DOMAIN_TYPE_PREFIX+analyticSubVolume.getName());
sbmlCSGObject.setOrdinal(analyticSubVolume.getHandle()); // the ordinal should be the least for the default/background subVolume
CSGObject backgroundObject = CSGObject.createBackgroundObject(vcOrigin, vcExtent, analyticSubVolume.getName(), analyticSubVolume.getHandle());
org.sbml.jsbml.ext.spatial.CSGNode sbmlcsgNode = getSBMLCSGNode(backgroundObject.getRoot());
sbmlcsgNode.setParent(sbmlCSGObject);
sbmlCSGObject.setCSGNode(sbmlcsgNode);
}
}
Expand Down Expand Up @@ -2315,26 +2327,26 @@ private boolean goodPointer(Object obj, Class<?> clzz, String sourceName) {
}

private static org.sbml.jsbml.ext.spatial.CSGNode getSBMLCSGNode(cbit.vcell.geometry.CSGNode vcCSGNode) {
String csgNodeName = vcCSGNode.getName();
String csgNodeName = "CSGObjectNode_"+vcCSGNode.getName();
if (vcCSGNode instanceof cbit.vcell.geometry.CSGPrimitive){
cbit.vcell.geometry.CSGPrimitive vcCSGprimitive = (cbit.vcell.geometry.CSGPrimitive)vcCSGNode;
org.sbml.jsbml.ext.spatial.CSGPrimitive sbmlPrimitive = new org.sbml.jsbml.ext.spatial.CSGPrimitive();
sbmlPrimitive.setSpatialId(csgNodeName);
switch (vcCSGprimitive.getType()){
case SPHERE: {
sbmlPrimitive.setPrimitiveType(SBMLSpatialConstants.SOLID_SPHERE);
sbmlPrimitive.setPrimitiveType(PrimitiveKind.sphere);
break;
}
case CONE: {
sbmlPrimitive.setPrimitiveType(SBMLSpatialConstants.SOLID_CONE);
sbmlPrimitive.setPrimitiveType(PrimitiveKind.cone);
break;
}
case CUBE: {
sbmlPrimitive.setPrimitiveType(SBMLSpatialConstants.SOLID_CUBE);
sbmlPrimitive.setPrimitiveType(PrimitiveKind.cube);
break;
}
case CYLINDER: {
sbmlPrimitive.setPrimitiveType(SBMLSpatialConstants.SOLID_CYLINDER);
sbmlPrimitive.setPrimitiveType(PrimitiveKind.cylinder);
break;
}
default: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,11 @@
package org.vcell.sbml.vcell;

import cbit.image.VCImage;
import cbit.image.VCImageCompressed;
import cbit.image.VCImageUncompressed;
import cbit.image.VCPixelClass;
import cbit.util.xml.VCLogger;
import cbit.util.xml.VCLoggerException;
import cbit.util.xml.XmlUtil;
import cbit.vcell.biomodel.BioModel;
import cbit.vcell.biomodel.ModelUnitConverter;
import cbit.vcell.biomodel.meta.VCMetaData;
import cbit.vcell.geometry.CSGObject;
import cbit.vcell.geometry.*;
Expand Down Expand Up @@ -49,7 +46,6 @@
import cbit.vcell.units.VCUnitDefinition;
import cbit.vcell.units.VCUnitSystem;
import cbit.vcell.xml.XMLTags;
import jscl.math.function.Exp;
import org.apache.commons.io.FileUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -71,7 +67,6 @@
import org.sbml.jsbml.xml.XMLNode;
import org.vcell.sbml.SBMLHelper;
import org.vcell.sbml.SBMLUtils;
import org.vcell.sbml.SbmlException;
import org.vcell.sbml.vcell.SBMLImportException.Category;
import org.vcell.util.*;
import org.vcell.util.BeanUtils.CastInfo;
Expand All @@ -87,7 +82,6 @@
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.zip.DataFormatException;

public class SBMLImporter {

Expand Down Expand Up @@ -3745,7 +3739,7 @@ private static void addGeometry(org.sbml.jsbml.Model sbmlModel, BioModel vcBioMo
// CSGObject[] vcCSGSubVolumes = new CSGObject[n];
for (int i = 0; i < n; i++) {
org.sbml.jsbml.ext.spatial.CSGObject sbmlCSGObject = sbmlCSGs.get(i);
CSGObject vcellCSGObject = new CSGObject(null, sbmlCSGObject.getSpatialId(), i);
CSGObject vcellCSGObject = new CSGObject(null, sbmlCSGObject.getDomainType(), i);
if (domainTypeId_to_handle_map.get(sbmlCSGObject.getDomainType()) != null){
vcellCSGObject.setHandle(domainTypeId_to_handle_map.get(sbmlCSGObject.getDomainType()));
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static Set<String> outOfMemorySet() {
public static Map<String, FAULT> knownFaults() {
HashMap<String, FAULT> faults = new HashMap();
faults.put("biomodel_123269393.vcml", FAULT.MATHOVERRIDES_INVALID); // Kf_r7
faults.put("biomodel_124562627.vcml", FAULT.NULL_POINTER_EXCEPTION);
faults.put("biomodel_124562627.vcml", FAULT.NULL_POINTER_EXCEPTION); // fails on CSG Geometry
faults.put("biomodel_156134818.vcml", FAULT.UNKNOWN_IDENTIFIER);
faults.put("biomodel_158495696.vcml", FAULT.EXPRESSIONS_DIFFERENT); // not lumped:
faults.put("biomodel_18894555.vcml", FAULT.MATHOVERRIDES_INVALID); // EGF_EC
Expand Down

0 comments on commit c452790

Please sign in to comment.