Search in sources :

Example 1 with MSRoot

use of ffx.potential.bonded.MSRoot 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 2 with MSRoot

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

the class MainPanel method initialize.

/**
 * <p>
 * initialize</p>
 */
public void initialize() {
    if (init) {
        return;
    }
    init = true;
    String dir = System.getProperty("user.dir", FileSystemView.getFileSystemView().getDefaultDirectory().getAbsolutePath());
    setCWD(new File(dir));
    locale = new FFXLocale("en", "US");
    JDialog splashScreen = null;
    ClassLoader loader = getClass().getClassLoader();
    if (!GraphicsEnvironment.isHeadless()) {
        // Splash Screen
        JFrame.setDefaultLookAndFeelDecorated(true);
        splashScreen = new JDialog(frame, false);
        ImageIcon logo = new ImageIcon(loader.getResource("ffx/ui/icons/splash.png"));
        JLabel ffxLabel = new JLabel(logo);
        ffxLabel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
        Container contentpane = splashScreen.getContentPane();
        contentpane.setLayout(new BorderLayout());
        contentpane.add(ffxLabel, BorderLayout.CENTER);
        splashScreen.setUndecorated(true);
        splashScreen.pack();
        Dimension screenDimension = getToolkit().getScreenSize();
        Dimension splashDimension = splashScreen.getSize();
        splashScreen.setLocation((screenDimension.width - splashDimension.width) / 2, (screenDimension.height - splashDimension.height) / 2);
        splashScreen.setResizable(false);
        splashScreen.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        splashScreen.setVisible(true);
        // Make all pop-up Menus Heavyweight so they play nicely with Java3D
        JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    }
    // Create the Root Node
    dataRoot = new MSRoot();
    Border bb = BorderFactory.createEtchedBorder(EtchedBorder.RAISED);
    statusLabel = new JLabel("  ");
    JLabel stepLabel = new JLabel("  ");
    stepLabel.setHorizontalAlignment(JLabel.RIGHT);
    JLabel energyLabel = new JLabel("  ");
    energyLabel.setHorizontalAlignment(JLabel.RIGHT);
    JPanel statusPanel = new JPanel(new GridLayout(1, 3));
    statusPanel.setBorder(bb);
    statusPanel.add(statusLabel);
    statusPanel.add(stepLabel);
    statusPanel.add(energyLabel);
    if (!GraphicsEnvironment.isHeadless()) {
        GraphicsConfigTemplate3D template3D = new GraphicsConfigTemplate3D();
        // template3D.setDoubleBuffer(GraphicsConfigTemplate.PREFERRED);
        GraphicsConfiguration gc = null;
        try {
            gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getBestConfiguration(template3D);
        // gc = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration();
        } catch (Exception e) {
            e.fillInStackTrace();
            e.printStackTrace();
            logger.log(Level.SEVERE, " Exception encountered when trying to get the best GraphicsConfiguration", e);
        }
        try {
            graphicsCanvas = new GraphicsCanvas(gc, this);
        } catch (Exception e) {
            e.fillInStackTrace();
            e.printStackTrace();
            logger.log(Level.SEVERE, " Exception encountered when trying to create the GraphicsCanvas", e);
        }
        graphicsPanel = new GraphicsPanel(graphicsCanvas, statusPanel);
    }
    // Initialize various Panels
    hierarchy = new Hierarchy(this);
    hierarchy.setStatus(statusLabel, stepLabel, energyLabel);
    keywordPanel = new KeywordPanel(this);
    modelingPanel = new ModelingPanel(this);
    JPanel treePane = new JPanel(new BorderLayout());
    JScrollPane scrollPane = new JScrollPane(hierarchy, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    treePane.add(scrollPane, BorderLayout.CENTER);
    tabbedPane = new JTabbedPane();
    ImageIcon graphicsIcon = new ImageIcon(loader.getResource("ffx/ui/icons/monitor.png"));
    ImageIcon keywordIcon = new ImageIcon(loader.getResource("ffx/ui/icons/key.png"));
    ImageIcon modelingIcon = new ImageIcon(loader.getResource("ffx/ui/icons/cog.png"));
    tabbedPane.addTab(locale.getValue("Graphics"), graphicsIcon, graphicsPanel);
    tabbedPane.addTab(locale.getValue("KeywordEditor"), keywordIcon, keywordPanel);
    tabbedPane.addTab(locale.getValue("ModelingCommands"), modelingIcon, modelingPanel);
    tabbedPane.addChangeListener(this);
    splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false, treePane, tabbedPane);
    /* splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, false,
         treePane, graphicsPanel); */
    splitPane.setResizeWeight(0.25);
    splitPane.setOneTouchExpandable(true);
    setLayout(new BorderLayout());
    add(splitPane, BorderLayout.CENTER);
    if (!GraphicsEnvironment.isHeadless()) {
        mainMenu = new MainMenu(this);
        add(mainMenu.getToolBar(), BorderLayout.NORTH);
        getModelingShell();
        loadPrefs();
        SwingUtilities.updateComponentTreeUI(SwingUtilities.getRoot(this));
        splashScreen.dispose();
    }
}
Also used : ImageIcon(javax.swing.ImageIcon) JPanel(javax.swing.JPanel) JTabbedPane(javax.swing.JTabbedPane) ForceFieldString(ffx.potential.parameters.ForceField.ForceFieldString) GraphicsConfiguration(java.awt.GraphicsConfiguration) Container(java.awt.Container) GridLayout(java.awt.GridLayout) BorderLayout(java.awt.BorderLayout) JScrollPane(javax.swing.JScrollPane) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) GraphicsConfigTemplate3D(javax.media.j3d.GraphicsConfigTemplate3D) UnsupportedLookAndFeelException(javax.swing.UnsupportedLookAndFeelException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) MalformedURLException(java.net.MalformedURLException) FFXLocale(ffx.ui.properties.FFXLocale) MSRoot(ffx.potential.bonded.MSRoot) JSplitPane(javax.swing.JSplitPane) File(java.io.File) Border(javax.swing.border.Border) EtchedBorder(javax.swing.border.EtchedBorder) JDialog(javax.swing.JDialog)

Example 3 with MSRoot

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

the class MainPanel method merge.

/**
 * Merge two or more selected FSystem Nodes into one FSystem node. There are
 * a few gotchas that need to be fixed
 *
 * @param nodesToMerge a {@link java.util.ArrayList} object.
 */
public void merge(ArrayList<MSNode> nodesToMerge) {
    ArrayList<MSNode> activeNodes = new ArrayList<MSNode>();
    for (MSNode node : nodesToMerge) {
        if (node != null && !(node instanceof MSRoot)) {
            activeNodes.add(node);
        }
    }
    if (activeNodes.size() <= 1) {
        return;
    }
    // Set up a structure to hold the new system
    FFXSystem active = hierarchy.getActive();
    File file = SystemFilter.version(hierarchy.getActive().getFile());
    FFXSystem system = new FFXSystem(file, "Merge Result", active.getProperties());
    system.setKeyFile(active.getKeyFile());
    system.setKeywords(KeyFilter.open(active.getKeyFile()));
    // Fill arrays with the atoms and bonds from the systems to be combined
    ArrayList<Atom> mergedAtoms = new ArrayList<Atom>();
    ArrayList<Bond> mergedBonds = new ArrayList<Bond>();
    ArrayList<FFXSystem> systems = new ArrayList<FFXSystem>();
    TransformGroup parentTransformGroup = null;
    FFXSystem parentSystem;
    Transform3D parentTransform3D = new Transform3D();
    Vector3d parentPosition = new Vector3d();
    Vector3d atomPosition = new Vector3d();
    // TINKER Atom Numbers start at 1
    int atomNum = 1;
    Vector3d zero = new Vector3d(0.0, 0.0, 0.0);
    for (MSNode m : activeNodes) {
        parentSystem = (FFXSystem) m.getMSNode(FFXSystem.class);
        if (parentSystem == null) {
            return;
        }
        if (!systems.contains(parentSystem)) {
            graphicsCanvas.updateSceneWait(parentSystem, false, true, RendererCache.ViewModel.WIREFRAME, false, null);
            systems.add(parentSystem);
        }
        // Move each atom into the global frame by applying the System
        // Transform to
        // relative atomic position
        parentTransformGroup = parentSystem.getOriginToRot();
        parentTransformGroup.getTransform(parentTransform3D);
        parentTransform3D.get(parentPosition);
        parentTransform3D.setTranslation(zero);
        // parentTransform3D.setScale(1.0d);
        ArrayList<Atom> atoms = m.getAtomList();
        ArrayList<ROLS> bonds = m.getBondList();
        for (Atom atom : atoms) {
            atom.removeFromParent();
            atom.setXyzIndex(atomNum++);
            mergedAtoms.add(atom);
            atom.getV3D(atomPosition);
            parentTransform3D.transform(atomPosition);
            atomPosition.add(parentPosition);
            atom.moveTo(atomPosition);
        }
        for (ROLS msm : bonds) {
            Bond bond = (Bond) msm;
            bond.removeFromParent();
            mergedBonds.add((Bond) msm);
        }
    }
    for (FFXSystem sys : systems) {
        close(sys);
    }
    MergeFilter mergeFilter = new MergeFilter(system, mergedAtoms, mergedBonds);
    UIFileOpener fileOpener = new UIFileOpener(mergeFilter, this);
    if (fileOpenerThreads > 0) {
        fileOpener.setNThreads(fileOpenerThreads);
    }
    Thread thread = new Thread(fileOpener);
    thread.start();
}
Also used : ROLS(ffx.potential.bonded.ROLS) Transform3D(javax.media.j3d.Transform3D) ArrayList(java.util.ArrayList) MergeFilter(ffx.potential.parsers.MergeFilter) Atom(ffx.potential.bonded.Atom) TransformGroup(javax.media.j3d.TransformGroup) MSNode(ffx.potential.bonded.MSNode) MSRoot(ffx.potential.bonded.MSRoot) Vector3d(javax.vecmath.Vector3d) Bond(ffx.potential.bonded.Bond) File(java.io.File)

Aggregations

MSRoot (ffx.potential.bonded.MSRoot)3 MSNode (ffx.potential.bonded.MSNode)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Atom (ffx.potential.bonded.Atom)1 Bond (ffx.potential.bonded.Bond)1 ROLS (ffx.potential.bonded.ROLS)1 ROLSP (ffx.potential.bonded.ROLSP)1 ForceFieldString (ffx.potential.parameters.ForceField.ForceFieldString)1 MergeFilter (ffx.potential.parsers.MergeFilter)1 FFXLocale (ffx.ui.properties.FFXLocale)1 BorderLayout (java.awt.BorderLayout)1 Container (java.awt.Container)1 Dimension (java.awt.Dimension)1 GraphicsConfiguration (java.awt.GraphicsConfiguration)1 GridLayout (java.awt.GridLayout)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 Enumeration (java.util.Enumeration)1