Package jSimMacs.jmol

Source Code of jSimMacs.jmol.JSimJmolAdapter$ProjectedAtomIterator

/**
* JSimJmolAdapter.java
*/
package jSimMacs.jmol;

import java.util.Hashtable;
import java.util.Properties;

import org.biojava.bio.structure.Atom;
import org.biojava.bio.structure.AtomImpl;
import org.biojava.bio.structure.Chain;
import org.biojava.bio.structure.Group;
import org.biojava.bio.structure.HetatomImpl;
import org.biojava.bio.structure.Structure;
import org.biojava.bio.structure.StructureImpl;
import org.biojava.bio.structure.StructureTools;
import org.jmol.api.JmolAdapter;

/**
* @author sr
* Adapter to combine jSimMacs, biojava, and JMol
*/
public class JSimJmolAdapter extends JmolAdapter {

  private Structure structure; //biojava object

  public JSimJmolAdapter() {
    super("JSimJMolAdapter");

    structure = new StructureImpl();
  }

  /**
   * @return Structure
   */
  public Structure getStructure() {
    return structure;
  }

  /**
   * sets Structure
   * @param structure
   */
  public void setStructure(Structure structure) {
    if (structure == null)
      structure = new StructureImpl();

    this.structure = structure;
  }

  /*
   * (non-Javadoc)
   *
   * @see org.jmol.api.JmolAdapter#getAtomIterator(java.lang.Object)
   */
  @Override
  public AtomIterator getAtomIterator(Object clientFile) {
    if ( ! (clientFile instanceof Structure)) {

            return new ProjectedAtomIterator(new StructureImpl());
        }
       
        return new ProjectedAtomIterator(structure);
  }

  /*
   * (non-Javadoc)
   *
   * @see org.jmol.api.JmolAdapter#getEstimatedAtomCount(java.lang.Object)
   */
  @Override
  public int getEstimatedAtomCount(Object arg0) {
    return StructureTools.getNrAtoms(structure);
  }
 
  /** return the number of models (each model is an AtomSet) **/
    public int getAtomSetCount(Object clientFile) {
        //logger.info("get atomsetcount " + structure.nrModels());
        return structure.nrModels();  
    }
   
   
    public String getAtomSetCollectionName(Object clientFile) {
        //logger.info("getAtomSetCollectionName");
        return null;
      }
     
      public Properties getAtomSetCollectionProperties(Object clientFile) {
          //logger.info("getAtomSetCollectionProperties");
        return null;
      }

      /**
       * Get Info of the Collection
       */
      public Hashtable getAtomSetCollectionAuxiliaryInfo(Object clientFile) {
        Hashtable tab = new Hashtable();
        tab.put("isPDB", new Boolean(true));
        return tab;
       
      }
     
      public boolean coordinatesAreFractional(Object clientFile) {
          return false;
      }

      public JmolAdapter.StructureIterator
          getStructureIterator(Object clientFile) {
         // logger.info("getStructureIterator");
          return null;
      }
     
     
      public int getAtomSetNumber(Object clientFile, int atomSetIndex) {       
              return atomSetIndex + 1;
      }

      public String getAtomSetName(Object clientFile, int atomSetIndex) {
         // logger.info("!!! getAtomSetName " + atomSetIndex);
            return null;
      }
     
      public Properties getAtomSetProperties(Object clientFile, int atomSetIndex) {
         // logger.info("getAtomSetProperties " + atomSetIndex);
          return null;
      }
     
      public Hashtable getAtomSetAuxiliaryInfo(Object clientFile, int atomSetIndex) {
         // logger.info("getAtomSetAuxiliaryInfo " + atomSetIndex);
          Hashtable tab = new Hashtable();
        return tab;
      }

      /**
       * @author sr
       * Combines the structure iterator with JmolAdapter AtomIterator
       */
  class ProjectedAtomIterator extends JmolAdapter.AtomIterator {
    Structure structure;
    Atom atom;
    org.biojava.bio.structure.AtomIterator iter;
    int pos;

    ProjectedAtomIterator(Structure structure) {
      // logger.info("new ProjectedAtomIterator");
      iter = new org.biojava.bio.structure.AtomIterator(structure);
      pos = 0;
      atom = new AtomImpl();
      this.structure = structure;

    }

    public String getElementSymbol() {
      // if ( atom.getPDBserial() < 200)
      // logger.info(atom.getParent().getPDBCode() + " " +
      // atom.getParent().getPDBName() + " " + atom.getPDBserial()+
      // atom.getFullName() + " " +
      // JmolUtils.deduceElementSymbol(atom.getFullName()));
      return JmolUtils.deduceElementSymbol(atom.getFullName());
      // return "Xx";
      // return super.getElementSymbol();
    }

    public boolean hasNext() {
      if (iter.hasNext()) {
        atom = (Atom) iter.next();
        pos++;
        return true;
      } else {
        return false;
      }
    }

    public Object getUniqueID() {

      return new Integer(pos);
    }

    public int getAtomSerial() {
      // return pos;
      return atom.getPDBserial();
    }

    public float getX() {

      return (float) atom.getX();
    }

    public float getY() {

      return (float) atom.getY();
    }

    public float getZ() {

      return (float) atom.getZ();
    }

    public String getAtomName() {
      // System.out.println(atom.getName());
      // return atom.getFullName();
      return atom.getName();
    }

    public String getGroup3() {

      Group parent = atom.getParent();
      if (parent != null) {

        return parent.getPDBName();
      }
      return null;
    }

    public int getSequenceNumber() {
      Group g = atom.getParent();
      if (g != null) {

        try {
          return Integer.parseInt(g.getPDBCode());
        } catch (NumberFormatException e) {
          // e.printStackTrace();
        }
      }

      return -1;
    }

    public char getChainID() {

      Chain c = iter.getCurrentChain();

      if (c != null) {

        String name = c.getName();
        if ((name != null) && (name.length() > 0)) {
          return name.charAt(0);
        }
      }

      return ' ';

    }

    public int getAtomSetIndex() {
      int idx = iter.getCurrentModel();
      // if ( structure.nrModels() > 1)
      // idx++;

      // System.out.println(idx + " " + atom.getParent().getPDBCode() + "
      // " + atom);

      return idx;
    }

    public char getAlternateLocationID() {
      if (atom.getAltLoc().charValue() != ' ') {
        return atom.getAltLoc().charValue();
      } else
        return (char) 0;
    }

    public char getInsertionCode() {
      Group g = atom.getParent();
      if (g != null) {
        String pdbresnum = g.getPDBCode();
        try {
          Integer.parseInt(pdbresnum);
        } catch (NumberFormatException ex) {

          String insertionCode = pdbresnum.substring(pdbresnum
              .length() - 2, pdbresnum.length());
          return insertionCode.charAt(0);
        }
      }
      return (char) 0;
    }

    public boolean getIsHetero() {
      Group parent = atom.getParent();
      if (parent != null) {
        if (parent.getType().equals(HetatomImpl.type)) {
          // System.out.println(atom + " is hetero");
          return true;
        }
      }

      return false;
    }

    public int getOccupancy() {

      // trying to match what Jmol does in PdbReader
      return (int) atom.getOccupancy() * 100;
    }

    public float getBfactor() {
      return (float) atom.getTempFactor();
    }

  }

}
TOP

Related Classes of jSimMacs.jmol.JSimJmolAdapter$ProjectedAtomIterator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.