Search in sources :

Example 16 with MSNode

use of ffx.potential.bonded.MSNode in project ffx by mjschnie.

the class MolecularAssembly method getNodeList.

/**
 * <p>
 * getNodeList</p>
 *
 * @return a {@link java.util.ArrayList} object.
 */
public ArrayList<MSNode> getNodeList() {
    ArrayList<MSNode> residues = new ArrayList<>();
    ListIterator<MSNode> li, lj;
    MSNode o;
    Polymer c;
    for (li = getAtomNodeList().listIterator(); li.hasNext(); ) {
        o = li.next();
        if (o instanceof Polymer) {
            c = (Polymer) o;
            for (lj = c.getAtomNodeList().listIterator(); lj.hasNext(); ) {
                o = lj.next();
                if (o instanceof Residue) {
                    residues.add(o);
                }
            }
        }
    }
    ArrayList<MSNode> list = ions.getChildList();
    for (MSNode node : list) {
        residues.add(node);
    }
    list = water.getChildList();
    for (MSNode node : list) {
        residues.add(node);
    }
    list = molecules.getChildList();
    for (MSNode node : list) {
        residues.add(node);
    }
    return residues;
}
Also used : MSNode(ffx.potential.bonded.MSNode) Residue(ffx.potential.bonded.Residue) ArrayList(java.util.ArrayList) Polymer(ffx.potential.bonded.Polymer)

Example 17 with MSNode

use of ffx.potential.bonded.MSNode in project ffx by mjschnie.

the class Renderer method processStimulus.

/**
 * {@inheritDoc}
 *
 * This method is called by the Java3D Behavior thread after the following
 * sequence of events: 1.) A graphics operation is loaded using the "arm"
 * method. 2.) The PostID call is processed by the Java3D Behavior Thread.
 */
@Override
public void processStimulus(Enumeration parm1) {
    // Do not perform two operations before the frame has be refreshed.
    if (getView().getFrameNumber() == frameNumber) {
        System.out.print(".");
        wakeupOn(postid);
        postId(1);
        return;
    }
    // Check that the requested View and Color Models are known.
    String viewString = null;
    String colorString = null;
    if (viewModel != null) {
        try {
            viewString = viewModel.toString();
        } catch (Exception e) {
            statusBar.setText("Unknown ViewModel: " + viewModel);
            return;
        }
    }
    if (colorModel != null) {
        try {
            colorString = colorModel.toString();
        } catch (Exception e) {
            statusBar.setText("Unknown ColorModel: " + colorModel);
            return;
        }
    }
    if (timer) {
        startTimer();
        if (viewString != null) {
            logger.info("Applying ViewModel Change: " + viewString);
        }
        if (colorString != null) {
            System.out.println("Applying ColorModel Change: " + colorString);
        }
    }
    // Perform the requested rendering operation
    ArrayList<ArrayList<BranchGroup>> newChildren = new ArrayList<ArrayList<BranchGroup>>();
    for (MSNode nodeToUpdate : nodesToUpdate) {
        if (nodeToUpdate == null) {
            continue;
        }
        if (doTransform) {
            nodeToUpdate.update();
        }
        if (doColor) {
            nodeToUpdate.setColor(colorModel, null, null);
            if (statusBar != null) {
                statusBar.setText("  Color by \"" + colorString + "\" applied to " + nodeToUpdate.toString());
            }
        }
        if (doView) {
            ArrayList<BranchGroup> newShapes = new ArrayList<BranchGroup>();
            newChildren.add(newShapes);
            nodeToUpdate.setView(viewModel, newShapes);
            if (statusBar != null) {
                statusBar.setText("  Style \"" + viewString + "\" applied to " + nodeToUpdate.toString());
            }
        }
    }
    // Wait for the parallel nodes to finish
    try {
        if (ROLSP.GO_PARALLEL && ROLSP.parallelNotDone > 0) {
            logger.info("Renderer waiting for " + ROLSP.parallelNotDone + " processes...");
        }
        while (ROLSP.GO_PARALLEL && ROLSP.parallelNotDone > 0) {
            synchronized (this) {
                wait(10);
            }
        }
    } catch (Exception e) {
        System.out.println("Exception Waiting for Parallel MultiScale Methods to Finish");
    } finally {
        // the MolecularAssembly.
        for (int i = 0; i < nodesToUpdate.size(); i++) {
            if (newChildren.isEmpty()) {
                break;
            }
            MSNode nodeToUpdate = nodesToUpdate.get(i);
            if (nodeToUpdate == null) {
                continue;
            }
            if (nodeToUpdate instanceof MolecularAssembly) {
                MolecularAssembly ma = (MolecularAssembly) nodeToUpdate;
                ma.sceneGraphChange(null);
            } else if (nodeToUpdate instanceof ROLSP) {
                MolecularAssembly ma = (MolecularAssembly) nodeToUpdate.getChildAt(0);
                ma.sceneGraphChange(null);
            } else if (nodeToUpdate instanceof MSRoot) {
                for (Enumeration e = nodeToUpdate.children(); e.hasMoreElements(); ) {
                    MSNode updatedNode = (MSNode) e.nextElement();
                    if (updatedNode instanceof ROLSP) {
                        MolecularAssembly ma = (MolecularAssembly) updatedNode.getChildAt(0);
                        ma.sceneGraphChange(null);
                    } else {
                        MolecularAssembly ma = (MolecularAssembly) updatedNode;
                        ma.sceneGraphChange(null);
                    }
                }
            } else {
                ArrayList<BranchGroup> newShapes = newChildren.get(i);
                if (!newShapes.isEmpty()) {
                    MolecularAssembly ma = (MolecularAssembly) nodeToUpdate.getMSNode(MolecularAssembly.class);
                    ma.sceneGraphChange(newShapes);
                }
            }
        }
    }
    if (timer) {
        stopTimer();
    }
    nodesToUpdate = null;
    wakeupOn(postid);
    if (nodesCache != null) {
        nodesToUpdate = nodesCache;
        doTransform = doTransformCache;
        doView = doViewCache;
        viewModel = viewModelCache;
        doColor = doColorCache;
        colorModel = colorModelCache;
        nodesCache = null;
        postId(1);
    }
}
Also used : MSNode(ffx.potential.bonded.MSNode) Enumeration(java.util.Enumeration) ROLSP(ffx.potential.bonded.ROLSP) BranchGroup(javax.media.j3d.BranchGroup) MSRoot(ffx.potential.bonded.MSRoot) ArrayList(java.util.ArrayList)

Example 18 with MSNode

use of ffx.potential.bonded.MSNode in project ffx by mjschnie.

the class ExtUtils method printTreeFromNode.

public static void printTreeFromNode(MSNode target) {
    StringBuilder sb = new StringBuilder();
    sb.append(format(" Tree Hierarchy for %s\n", target.getName()));
    sb.append(format(" ===================%s\n", StringUtils.repeat("=", target.getName().length())));
    TreeNode root = target;
    while (root.getParent() != null) {
        root = root.getParent();
    }
    Enumeration<?> fromRoot = target.pathFromAncestorEnumeration(root);
    List<MSNode> toLeaves = target.getDescendants(MSNode.class);
    boolean init = false;
    for (MSNode node : toLeaves) {
        if (!init) {
            sb.append(format(" %s> %s\n", StringUtils.repeat(">", node.getLevel()), node.getName()));
            init = true;
            continue;
        }
        if (!node.getName().isEmpty()) {
            sb.append(format(" └%s> %s\n", StringUtils.repeat("-", node.getLevel()), node.getName()));
        }
    }
    logger.info(sb.toString());
}
Also used : MSNode(ffx.potential.bonded.MSNode) TreeNode(javax.swing.tree.TreeNode)

Example 19 with MSNode

use of ffx.potential.bonded.MSNode in project ffx by mjschnie.

the class COMRestraint method computedcomdx.

private void computedcomdx() {
    // double totalMass = 0.0;
    int i = 0;
    while (i < nAtoms) {
        if (polymers != null && polymers.length > 0) {
            for (Polymer polymer : polymers) {
                List<Atom> list = polymer.getAtomList();
                double totalMass = 0.0;
                for (Atom atom : list) {
                    double m = atom.getMass();
                    totalMass += m;
                }
                for (Atom atom : list) {
                    dcomdx[i] = atom.getMass();
                    dcomdx[i] /= totalMass;
                    i++;
                }
            }
        }
        // Loop over each molecule
        for (MSNode molecule : molecules) {
            List<Atom> list = molecule.getAtomList();
            double totalMass = 0.0;
            for (Atom atom : list) {
                double m = atom.getMass();
                totalMass += m;
            }
            for (Atom atom : list) {
                dcomdx[i] = atom.getMass();
                dcomdx[i] /= totalMass;
                i++;
            }
        }
        // Loop over each water
        for (MSNode water : waters) {
            List<Atom> list = water.getAtomList();
            double totalMass = 0.0;
            for (Atom atom : list) {
                double m = atom.getMass();
                totalMass += m;
            }
            for (Atom atom : list) {
                dcomdx[i] = atom.getMass();
                dcomdx[i] /= totalMass;
                i++;
            }
        }
        // Loop over each ion
        for (MSNode ion : ions) {
            List<Atom> list = ion.getAtomList();
            double totalMass = 0.0;
            for (Atom atom : list) {
                double m = atom.getMass();
                totalMass += m;
            }
            for (Atom atom : list) {
                dcomdx[i] = atom.getMass();
                dcomdx[i] /= totalMass;
                i++;
            }
        }
    }
// for (int i = 0; i < nAtoms; i++) {
// Atom a = atoms[i];
// dcomdx[j] = a.getMass() / totalMass;
// }
}
Also used : MSNode(ffx.potential.bonded.MSNode) Polymer(ffx.potential.bonded.Polymer) Atom(ffx.potential.bonded.Atom)

Example 20 with MSNode

use of ffx.potential.bonded.MSNode in project ffx by mjschnie.

the class Hierarchy method valueChanged.

/**
 * {@inheritDoc}
 */
@Override
public void valueChanged(TreeSelectionEvent e) {
    synchronized (this) {
        // Determine the Active System
        MSNode lastNode = (MSNode) getLastSelectedPathComponent();
        if (lastNode != null) {
            activeNode = lastNode;
            FFXSystem s = (FFXSystem) activeNode.getMSNode(FFXSystem.class);
            if (s != null) {
                setActive(s);
            }
        }
        TreePath[] paths = e.getPaths();
        if (paths == null) {
            return;
        }
        // Reuse the same ArrayLists
        ArrayList<TreePath> temp = previousPaths;
        previousPaths = newPaths;
        newPaths = temp;
        // Determine new and removed paths
        newPaths.clear();
        removedPaths.clear();
        for (int i = 0; i < paths.length; i++) {
            if (e.isAddedPath(i)) {
                newPaths.add(paths[i]);
            } else {
                removedPaths.add(paths[i]);
            }
        }
        // Create a non-redundant set of new/removed paths
        TreePath pathi, pathj;
        for (int i = 0; i < newPaths.size(); i++) {
            pathi = newPaths.get(i);
            if (pathi == nullPath) {
                continue;
            }
            for (int j = i + 1; j < newPaths.size(); j++) {
                pathj = newPaths.get(j);
                if (pathi == nullPath || pathj == nullPath) {
                    continue;
                }
                if (pathi.isDescendant(pathj)) {
                    newPaths.set(j, nullPath);
                } else if (pathj.isDescendant(pathi)) {
                    newPaths.set(i, nullPath);
                }
            }
        }
        boolean check = true;
        while (check) {
            check = newPaths.remove(nullPath);
        }
        for (int i = 0; i < removedPaths.size(); i++) {
            pathi = removedPaths.get(i);
            if (pathi == nullPath) {
                continue;
            }
            for (int j = i + 1; j < removedPaths.size(); j++) {
                pathj = removedPaths.get(j);
                if (pathi == nullPath || pathj == nullPath) {
                    continue;
                }
                if (pathi.isDescendant(pathj)) {
                    removedPaths.set(j, nullPath);
                } else if (pathj.isDescendant(pathi)) {
                    removedPaths.set(i, nullPath);
                }
            }
        }
        check = true;
        while (check) {
            check = removedPaths.remove(nullPath);
        }
        // Remove the RemovedPaths from the Existing List
        for (int i = 0; i < previousPaths.size(); i++) {
            pathi = previousPaths.get(i);
            for (TreePath removedPath : removedPaths) {
                if (removedPath.isDescendant(pathi)) {
                    previousPaths.set(i, nullPath);
                    break;
                }
            }
        }
        check = true;
        while (check) {
            check = previousPaths.remove(nullPath);
        }
        // Combine new Paths and Existing Paths non-redundantly
        for (int i = 0; i < newPaths.size(); i++) {
            pathi = newPaths.get(i);
            if (pathi == nullPath) {
                continue;
            }
            for (int j = 0; j < previousPaths.size(); j++) {
                pathj = previousPaths.get(j);
                if (pathj == nullPath) {
                    continue;
                }
                if (pathi == nullPath || pathj == nullPath) {
                    continue;
                }
                if (pathi.isDescendant(pathj)) {
                    previousPaths.set(j, nullPath);
                } else if (pathj.isDescendant(pathi)) {
                    newPaths.set(i, nullPath);
                }
            }
        }
        check = true;
        while (check) {
            check = newPaths.remove(nullPath);
        }
        check = true;
        while (check) {
            check = previousPaths.remove(nullPath);
        }
        newPaths.addAll(previousPaths);
        activeNodes.clear();
        for (TreePath newPath : newPaths) {
            pathi = newPath;
            activeNodes.add((MSNode) pathi.getLastPathComponent());
        }
        if (activeNode != null) {
            TreePath activePath = new TreePath(activeNode);
            expandPath(activePath.getParentPath());
            makeVisible(activePath);
            scrollPathToVisible(activePath);
        }
        // We now have a non-redundant set of Active Paths; and a
        // non-redundant set of removed paths
        picks = new ArrayList<>();
        // Clear highlight of de-selected nodes
        for (TreePath r : removedPaths) {
            boolean change = true;
            for (TreePath n : newPaths) {
                if (n.isDescendant(r)) {
                    change = false;
                }
            }
            if (change) {
                MSNode f = (MSNode) r.getLastPathComponent();
                f.setSelected(false);
                picks.add(f);
            }
        }
        for (TreePath n : newPaths) {
            boolean change = true;
            for (TreePath p : previousPaths) {
                if (p.isDescendant(n)) {
                    change = false;
                }
            }
            if (change) {
                MSNode f = (MSNode) n.getLastPathComponent();
                f.setSelected(true);
                picks.add(f);
            }
        }
        if (RendererCache.highlightSelections) {
            mainPanel.getGraphics3D().updateScene(picks, false, false, null, true, RendererCache.ColorModel.SELECT);
        } else if (RendererCache.labelAtoms || RendererCache.labelResidues) {
            mainPanel.getGraphics3D().setLabelsUpdated();
        }
    }
}
Also used : MSNode(ffx.potential.bonded.MSNode) TreePath(javax.swing.tree.TreePath)

Aggregations

MSNode (ffx.potential.bonded.MSNode)39 Atom (ffx.potential.bonded.Atom)21 Polymer (ffx.potential.bonded.Polymer)20 Molecule (ffx.potential.bonded.Molecule)16 Residue (ffx.potential.bonded.Residue)13 ArrayList (java.util.ArrayList)9 MolecularAssembly (ffx.potential.MolecularAssembly)7 Bond (ffx.potential.bonded.Bond)7 MissingAtomTypeException (ffx.potential.bonded.BondedUtils.MissingAtomTypeException)6 MissingHeavyAtomException (ffx.potential.bonded.BondedUtils.MissingHeavyAtomException)6 IOException (java.io.IOException)6 Crystal (ffx.crystal.Crystal)5 File (java.io.File)5 MSGroup (ffx.potential.bonded.MSGroup)4 BufferedWriter (java.io.BufferedWriter)4 FileWriter (java.io.FileWriter)4 HashMap (java.util.HashMap)3 List (java.util.List)3 MSRoot (ffx.potential.bonded.MSRoot)2 ROLS (ffx.potential.bonded.ROLS)2