// Method to load file from BioJava structure to Jmol Display public void loadFileToJmol(Structure struc) { createUserModel(struc); String pdb = DataManager.modelToPDB(modelList); viewer.openStringInline(pdb); toolPanel.setModelText(modelList); logger.log(Level.INFO, "After load File: "); }
// paste copied/cut atoms, not applicable when copied atoms are paste to same model. public void pasteSavedAtoms(int modelIndex) { if (savedAtoms == null) JOptionPane.showMessageDialog( jmolPanel, "You have not copied or cut any atoms to paste!", "Warning", JOptionPane.WARNING_MESSAGE); else { boolean error = false; for (int i = 0; i < savedAtoms.size(); i++) { for (Atom atm : modelList.get(modelIndex).getAtomHash().values()) { if (savedAtoms.get(i).getCoordinates()[0] == atm.getCoordinates()[0] && savedAtoms.get(i).getCoordinates()[1] == atm.getCoordinates()[1] && savedAtoms.get(i).getCoordinates()[2] == atm.getCoordinates()[2]) { error = true; break; } } if (error) { JOptionPane.showMessageDialog( jmolPanel, "You are trying to paste atoms in location occupied!", "Warning", JOptionPane.WARNING_MESSAGE); break; } else { addAtom(modelIndex, savedAtoms.get(i)); } } String pdb = DataManager.modelToPDB(modelList); System.out.println(pdb); viewer.openStringInline(pdb); viewer.setCurrentModelIndex(modelIndex); } toolPanel.setModelText(modelList); }
public void displayParticles(ArrayList<AbstractParticle> list) { String pdb = "MODEL 1\n"; for (int i = 0; i < list.size(); i++) { // String index = String.format("%4d", list.get(i).getGUID()); String index = String.format("%4d", i); if (list.get(i) instanceof Atom) { double scale = Math.pow(10, 10 + list.get(i).getPosition().metric); Vector3D position = list.get(i).getPosition(); double x = capCoord(position.x * scale); double y = capCoord(position.y * scale); double z = capCoord(position.z * scale); String coords = String.format("%8.3f%8.3f%8.3f", x, y, z); String elementSymbol = String.format("%-4s", ((Atom) list.get(i)).getElementSymbol().toUpperCase()); pdb += "HETATM " + index + " " + elementSymbol + " 1 " + coords + " 1.00 0.00\n"; } else if (list.get(i) instanceof Molecule) { Molecule m = (Molecule) list.get(i); if (World.simulationLvlAtomic == true) { for (Atom a : m.getChains().get(0).atomSeq) { double scale = Math.pow(10, 10 + list.get(i).getPosition().metric); Vector3D position = a.getPosition(); double x = capCoord(position.x * scale); double y = capCoord(position.y * scale); double z = capCoord(position.z * scale); String coords = String.format("%8.3f%8.3f%8.3f", x, y, z); String elementSymbol = String.format("%-4s", a.getElementSymbol().toUpperCase()); pdb += "HETATM " + index + " " + elementSymbol + " 1 " + coords + " 1.00 0.00\n"; } /* pdb += "HETATM 1 NA TST A 1 5.000 5.000 5.000 1.00 0.00\n"+ "HETATM 2 CL TST A 1 6.400 6.400 6.400 1.00 0.00\n"+ "CONECT 1 2\n" + "CONECT 2 1\n"; */ } else { double scale = Math.pow(10, 10 + list.get(i).getPosition().metric); Vector3D position = list.get(i).getPosition(); double x = capCoord(position.x * scale); double y = capCoord(position.y * scale); double z = capCoord(position.z * scale); String coords = String.format("%8.3f%8.3f%8.3f", x, y, z); pdb += "HETATM 1 CS TST A 1 " + coords + " 1.00 0.00\n"; } } } pdb += "ENDMDL"; if (World.displayUI) viewer.openStringInline(pdb); try { BufferedWriter writer = new BufferedWriter(new FileWriter("output.pdb")); writer.write(pdb); writer.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); World.simulationStatus = "restart"; } if (World.displayUI) { createUserModel(DataManager.readFile("output.pdb")); } }
/** Create the main frame. */ public View(EventListener listener, Map<String, Object> config) { super((String) config.get("name")); this.listener = listener; this.config = config; setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 900, 600); setLocationRelativeTo(null); contentPane = new JPanel(); contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); contentPane.setLayout(new BorderLayout(0, 0)); setContentPane(contentPane); // add JMol Panel JmolDisplay jmolPanel = new JmolDisplay(); jmolPanel.setBorder(new EmptyBorder(5, 0, 5, 0)); contentPane.add(jmolPanel); // add mediator viewer = jmolPanel.getViewer(); viewer.evalString("set debug OFF;"); mediator = new UpdateRegistry(viewer); jmolPanel.setMediator(mediator); viewer.setPercentVdwAtom(20); viewer.evalString(""); System.out.println((String) config.get("pdb")); viewer.reset(true); viewer.openStringInline((String) config.get("pdb")); // viewer.evalString("load " + (String) config.get("dir") + "/" + (String) config.get("name") + // "/" + (String) config.get("name") + ".gro"); viewer.evalString("wireframe only;wireframe reset;spacefill reset;"); // viewer.evalString("set mouseDragFactor 1.0"); jmolPanel.setMediator(mediator); // add RHS Panel for user input JPanel inputPanel = new JPanel(); inputPanel.setBorder(new EmptyBorder(0, 5, 0, 5)); contentPane.add(inputPanel, BorderLayout.EAST); createSimulationPanel(); inputPanel.setLayout(new BorderLayout(0, 1)); inputPanel.add(simulationPanel, BorderLayout.NORTH); createForcesPanel(); inputPanel.add(forcesPanel, BorderLayout.CENTER); controlPanel = new JPanel(); controlPanel.setAlignmentX(LEFT_ALIGNMENT); inputPanel.add(controlPanel, BorderLayout.SOUTH); pauseButton = new JButton("Pause"); pauseButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (listener.getStatus() > 0) { pauseButton.setText("Resume"); partialEnableSimulationPanel(); enableForcePanel(); listener.onPause(); } else { pauseButton.setText("Pause"); saveParams(); disableForcePanel(); disableSimulationPanel(); listener.onResume(); } } }); controlPanel.add(pauseButton); stopButton = new JButton("Stop"); stopButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (stopButton.getText().equals("Stop")) { stopButton.setText("Start"); pauseButton.setEnabled(false); enableConfig(); listener.onStop(); } else { stopButton.setText("Stop"); pauseButton.setText("Pause"); pauseButton.setEnabled(true); saveParams(); listener.onRestart(); System.out.println("restart done"); } } }); controlPanel.add(stopButton); restartButton = new JButton("Restart"); restartButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stopButton.setText("Stop"); pauseButton.setText("Pause"); pauseButton.setEnabled(true); saveParams(); listener.onRestart(); } }); controlPanel.add(restartButton); // add text field for user input // commandTextField = new JTextField(); // contentPane.add(commandTextField, BorderLayout.SOUTH); // commandTextField.requestFocusInWindow(); this.setVisible(true); }
private void reloadViewer() { viewer.reset(true); viewer.openStringInline((String) config.get("pdb")); // viewer.evalString("load " + (String) config.get("dir") + (String) config.get("name") + "/" + // (String) config.get("name") + ".gro"); }