import java.math.*; import java.util.*; import neuroml.meta.*; import neuroml.util.*; import neuroml.morph.*; import static java.lang.Math.*; /** * This class calculates the total membrane surface area * of a set of segments belonging to a group named "dendrite_group". * * @author mschachter * */ public class SACalculator { /** * Compute the total membrane surface area for all the segments * for a specified Morphology in a given region. * * @param morph The Morphology * @param groupName The group to tally the total SA of. * @return The total membrane surface area (um^2) * @throws Exception If something goes wrong. */ public static double computeTotalSA(Morphology morph, String groupName) throws Exception { //get cell (index 0) from cell list Cell mossCell = morph.getCellList().get(0); //get list of cables List cbls = mossCell.getCableList(); //re-organize the cable list into a Map for easy lookup by id Map cblMap = new HashMap(); for (Cable c : cbls) cblMap.put(c.getId(), c); double totalSA = 0; //get list of segments, compute surface area of each //and add to the total List segList = mossCell.getSegmentList(); Point prox, dist; Cable c; double len; List groups; for (Segment s : segList) { //make sure cable exists if (!cblMap.containsKey(s.getCable())) throw new Exception("Cable " + s.getCable().toString() + " not found!"); //get associated cable and groups it belongs in c = cblMap.get(s.getCable()); groups = c.getGroup(); //only add to total if the cable is in the right group if (groups.contains(groupName)) { prox = s.getProximal(); dist = s.getDistal(); //compute length of segment len = sqrt( pow(abs(prox.getX()-dist.getX()), 2) + pow(abs(prox.getY()-dist.getY()), 2) + pow(abs(prox.getZ()-dist.getZ()), 2) ); //add surface area to total totalSA += PI*.5*(prox.getDiameter() + dist.getDiameter())* sqrt(.5*(prox.getDiameter() - dist.getDiameter()) + pow(len,2)); } } return totalSA; } public static void main(String args[]) { try { //create NeuroMLConverter instance NeuroMLConverter nc = new NeuroMLConverter(); //read morphology from file Morphology morph = nc.xmlToMorphology("MossyCell.xml"); //compute the total surface area of the segments //that belong to the group "dendrite_group" double totalSA = SACalculator.computeTotalSA(morph, "dendrite_group"); System.err.println("Total membrane surface area: " + totalSA + " um^2"); } catch (Exception e) { e.printStackTrace(System.err); } } }