// delete Atoms from both modelList and viewer.
 public void deleteAtoms(int currentModelIndex, String key, int atomPosition) {
   modelList.get(currentModelIndex).removeAtom(key);
   // modelList.get(currentModelIndex).getAtomHash().remove(key);
   viewer.evalString(
       "delete atomno=" + atomPosition + " && modelindex=" + viewer.getDisplayModelIndex());
   toolPanel.setModelText(modelList);
 }
  public void notifyUpdated(AbstractParticle[] particles) {
    List<Atom> atomsUpdated = new ArrayList<Atom>();

    // When the two particles are part of common model
    if (modelList.size() != 0) {
      for (int i = 0; i < particles.length; i++) {
        if (particles[i] instanceof Atom) { // if particle is Atom type
          // get the updated atom from model
          atomsUpdated.add(
              modelList
                  .get(0)
                  .getAtomHash()
                  .get(modelList.get(0).getModelName() + ((Atom) particles[i]).getChainSeqNum()));
        }
      }
      // update atoms in jmol display
      for (int i = 0; i < atomsUpdated.size(); i++) {
        Atom atom = atomsUpdated.get(i);
        float xOffset =
            (float) atom.getPosition().x - viewer.getAtomPoint3f(atom.getChainSeqNum() - 1).x;
        float yOffset =
            (float) atom.getPosition().y - viewer.getAtomPoint3f(atom.getChainSeqNum() - 1).y;
        float zOffset =
            (float) atom.getPosition().z - viewer.getAtomPoint3f(atom.getChainSeqNum() - 1).z;
        viewer.evalString("select atomno=" + atom.getChainSeqNum());
        viewer.evalString("translateSelected {" + xOffset + " " + yOffset + " " + zOffset + "}");
      }
    }
  }
 private String getAuxiliaryFileData() {
   String fName = fileName.substring(fileName.lastIndexOf("/") + 1);
   fName = fName.substring(fName.lastIndexOf("\\") + 1);
   return "; Created by: Jmol "
       + Viewer.getJmolVersion()
       + "\n; Creation date: "
       + getExportDate()
       + "\n; File created: "
       + fileName
       + " ("
       + out.getByteCount()
       + " bytes)\n\n"
       + (commandLineOptions != null
           ? commandLineOptions
           : "\n; Jmol state: (embedded in input file)"
               + "\nInput_File_Name="
               + fName
               + "\nOutput_to_File=true"
               + "\nOutput_File_Type=N"
               + "\nOutput_File_Name="
               + fName
               + ".png"
               + "\nWidth="
               + screenWidth
               + "\nHeight="
               + screenHeight
               + "\nAntialias=true"
               + "\nAntialias_Threshold=0.1"
               + "\nDisplay=true"
               + "\nPause_When_Done=true"
               + "\nWarning_Level=5"
               + "\nVerbose=false"
               + "\n");
 }
  // called by JMolSelectionListener.java to set the selected Atoms list
  public void setSelectedAtoms(BS values) {
    // System.out.println("Selected: " + values);
    if (selectedAtoms == null) selectedAtoms = new ArrayList<Atom>();
    else selectedAtoms.clear();

    String[] valueGet = values.toString().split("[{ }]");
    if (modelList != null) {
      Model currentModel = modelList.get(viewer.getDisplayModelIndex());
      for (int i = 0; i < valueGet.length; i++) {
        if (valueGet[i].compareTo("") != 0) {
          // if its list of continuous atoms
          if (valueGet[i].contains(":")) {
            int start = Integer.parseInt(valueGet[i].split(":")[0]) + 1;
            int end = Integer.parseInt(valueGet[i].split(":")[1]) + 1;
            for (int j = start; j <= end; j++) {
              selectedAtoms.add(currentModel.getAtomHash().get(currentModel.getModelName() + j));
            }
          } else {
            selectedAtoms.add(
                currentModel
                    .getAtomHash()
                    .get(currentModel.getModelName() + (Integer.parseInt(valueGet[i]) + 1)));
          }
        }
      }
    }
  }
 // 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: ");
 }
 // define minimizer, for minimizing molecule.
 public void minimizeModel() {
   // viewer.ms.setAtomCoord(0, 0.0f, 0.0f, 0.0f);
   Minimizer minimizer = new Minimizer(this);
   minimizer.setupMinimizing(modelList.get(viewer.getDisplayModelIndex()));
   minimizer.startMinimizing();
   System.out.println(DataManager.modelToPDB(modelList));
   minimizeMode = false;
 }
 public void updateViewerCoord() {
   for (Atom atm : modelList.get(viewer.getDisplayModelIndex()).getAtomHash().values()) {
     viewer.ms.setAtomCoord(
         (atm.getAtomSeqNum() - 1),
         atm.getCoordinates()[0],
         atm.getCoordinates()[1],
         atm.getCoordinates()[2]);
   }
   jmolPanel.getViewer().refresh(3, "minimization step ");
 }
 public void atomMoved() {
   for (Atom atm : modelList.get(viewer.getDisplayModelIndex()).getAtomHash().values()) {
     for (int i = 0; i < viewer.ms.at.length; i++) {
       if (atm.getAtomSeqNum() == (i + 1)) {
         double[] coords = {viewer.ms.at[i].x, viewer.ms.at[i].y, viewer.ms.at[i].z};
         atm.setCoordinates(coords);
       }
     }
   }
 }
  // 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);
  }
  // every mouse state and detection called here.
  // to cater for future self-created display.
  public void setMouseState(int x, int y, int mode) {
    GestureManager.setMouseState(x, y, mode, mouseState);
    if (viewer.getInMotion(false)) {

      /*String mouseGesture = "";
      mouseGesture += "Mouse Mode: " + mouseState.getMouseMode() + "\n";
      mouseGesture += "Mouse Start Position: X-Pos=" + mouseState.getStartPosX() + " Y-Pos=" + mouseState.getStartPosY() + "\n";
      mouseGesture += "Mouse End Position: X-Pos=" + mouseState.getEndPosX() + " Y-Pos=" + mouseState.getEndPosY() + "\n";*/
      // System.out.println(mouseGesture);
      mouseState.clearState();
    }
    if (minimizeMode && mode == 16640) { // when mouse drag stopped.
      System.out.println("Entering minimizing stage...");
      minimizeModel();
    }
  }
Example #11
0
 public void steepestDescentInitialize(int stepMax, double criterion) {
   this.stepMax = stepMax; // 1000
   // The criterion must be in the units of the calculation.
   // However, the user is setting this, so they will be in Minimizer units.
   //
   this.criterion = criterion / toUserUnits(1); // 1e-3
   currentStep = 0;
   clearForces();
   calc.setLoggingEnabled(true);
   calc.setLoggingEnabled(stepMax == 0 || Logger.isActiveLevel(Logger.LEVEL_DEBUGHIGH));
   String s =
       name
           + " "
           + calc.getDebugHeader(-1)
           + "Jmol Minimization Version "
           + Viewer.getJmolVersion()
           + "\n";
   calc.appendLogData(s);
   Logger.info(s);
   calc.getConstraintList();
   if (calc.loggingEnabled)
     calc.appendLogData(calc.getAtomList("S T E E P E S T   D E S C E N T"));
   dE = 0;
   calc.setPreliminary(stepMax > 0);
   e0 = energyFull(false, false);
   s =
       TextFormat.sprintf(
           " Initial "
               + name
               + " E = %10.3f "
               + minimizer.units
               + " criterion = %8.6f max steps = "
               + stepMax,
           new Object[] {Float.valueOf(toUserUnits(e0)), Float.valueOf(toUserUnits(criterion))});
   minimizer.report(s, false);
   calc.appendLogData(s);
 }
Example #12
0
 /**
  * legacy apps will use this
  *
  * @param vwr
  * @param g
  * @param size
  */
 @Deprecated
 static void renderScreenImage(PlatformViewer vwr, Object g, Object size) {
   ((Viewer) vwr).renderScreenImage(g, ((Dimension) size).width, ((Dimension) size).height);
 }
  @Override
  protected void outputHeader() {
    initVars();
    output("// ******************************************************\n");
    output("// Created by Jmol " + Viewer.getJmolVersion() + "\n");
    output("//\n");
    output("// This script was generated on " + getExportDate() + "\n");
    output("// ******************************************************\n");
    try {
      output(viewer.getWrappedStateScript());
    } catch (Exception e) {
      // tough luck
    }
    output("\n");
    output("// ******************************************************\n");
    output("// Declare the resolution, camera, and light sources.\n");
    output("// ******************************************************\n");
    output("\n");
    output("// NOTE: if you plan to render at a different resolution,\n");
    output("// be sure to update the following two lines to maintain\n");
    output("// the correct aspect ratio.\n" + "\n");
    output("#declare Width = " + screenWidth + ";\n");
    output("#declare Height = " + screenHeight + ";\n");
    output("#declare minScreenDimension = " + minScreenDimension + ";\n");
    output("#declare showAtoms = true;\n");
    output("#declare showBonds = true;\n");
    output("#declare noShadows = true;\n");
    output("camera{\n");
    output("  orthographic\n");
    output("  location < " + screenWidth / 2f + ", " + screenHeight / 2f + ", 0>\n" + "\n");
    output("  // Negative right for a right hand coordinate system.\n");
    output("\n");
    output("  sky < 0, -1, 0 >\n");
    output("  right < -" + screenWidth + ", 0, 0>\n");
    output("  up < 0, " + screenHeight + ", 0 >\n");
    output("  look_at < " + screenWidth / 2f + ", " + screenHeight / 2f + ", 1000 >\n");
    output("}\n");
    output("\n");

    output("background { color rgb <" + rgbFractionalFromColix(backgroundColix) + "> }\n");
    output("\n");

    // light source

    float distance = Math.max(screenWidth, screenHeight);
    output(
        "light_source { <"
            + lightSource.x * distance
            + ","
            + lightSource.y * distance
            + ", "
            + (-1 * lightSource.z * distance)
            + "> "
            + " rgb <0.6,0.6,0.6> }\n");
    output("\n");
    output("\n");

    output("// ***********************************************\n");
    output("// macros for common shapes\n");
    output("// ***********************************************\n");
    output("\n");

    writeMacros();
  }
  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");
 }