home *** CD-ROM | disk | FTP | other *** search
/ Enter 2004 June / ENTER.ISO / files / xampp-win32-1.4.5-installer.exe / xampp / Atom_PDB.php < prev    next >
Encoding:
PHP Script  |  2004-03-24  |  6.4 KB  |  225 lines

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 4                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2003 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net>                |
  17. // +----------------------------------------------------------------------+
  18. //
  19. // $Id: Atom_PDB.php,v 1.5 2003/05/13 01:18:17 jmcastagnetto Exp $
  20. //
  21.  
  22. require_once "Science/Chemistry/Atom.php" ;
  23.  
  24. /**
  25.  * Represents a PDB atom record
  26.  * and contains a reference to the PDB residue to which it belongs
  27.  *
  28.  * @author  Jesus M. Castagnetto <jmcastagnetto@php.net>
  29.  * @version 1.0
  30.  * @access  public
  31.  * @package Science_Chemistry
  32.  */
  33. class Science_Chemistry_Atom_PDB extends Science_Chemistry_Atom {
  34.  
  35.     /**
  36.      * PDB Atom record type, one of ATOM or HETATM
  37.      *
  38.      * @var     string
  39.      * @access  private
  40.      * @see     getField()
  41.      */
  42.     var $rec_name;
  43.  
  44.     /**
  45.      * PDB Atom serial number
  46.      *
  47.      * @var     integer
  48.      * @access   private
  49.      * @see     getField()
  50.      */
  51.     var $ser_num;
  52.  
  53.     /**
  54.      * PDB Atom name
  55.      *
  56.      * @var     string
  57.      * @access  private
  58.      * @see     getField()
  59.      */
  60.     var $atom_name;
  61.  
  62.     /**
  63.      * PDB Atom alternative location
  64.      *
  65.      * @var     string
  66.      * @access  private
  67.      * @see     getField()
  68.      */
  69.     var $alt_loc;
  70.  
  71.     /**
  72.      * PDB Atom's Residue name
  73.      *
  74.      * @var     string
  75.      * @access  private
  76.      * @see     getField()
  77.      */
  78.     var $res_name;
  79.  
  80.     /**
  81.      * PDB Atom's Residue chain ID
  82.      *
  83.      * @var     string
  84.      * @access  private
  85.      * @see     getField()
  86.      */
  87.     var $chain_id;
  88.  
  89.     /**
  90.      * PDB Atom's Residue sequential numnber
  91.      *
  92.      * @var     string
  93.      * @access  private
  94.      * @see     getField()
  95.      */
  96.     var $res_seq_num;
  97.  
  98.     /**
  99.      * PDB Atom insert code
  100.      *
  101.      * @var     string
  102.      * @access  private
  103.      * @see     getField()
  104.      */
  105.     var $ins_code;
  106.  
  107.     /**
  108.      * PDB Atom occupancy
  109.      *
  110.      * @var     float
  111.      * @access  private
  112.      * @see     getField()
  113.      */
  114.     var $occupancy;
  115.  
  116.     /**
  117.      * PDB Atom temperature factor
  118.      *
  119.      * @var     float
  120.      * @access  private
  121.      * @see     getField()
  122.      */
  123.     var $temp_factor;
  124.  
  125.     /**
  126.      * PDB Atom segment identifier
  127.      *
  128.      * @var     string
  129.      * @access  private
  130.      * @see     getField()
  131.      */
  132.     var $segment_id;
  133.  
  134.     /**
  135.      * PDB Atom electronic charge
  136.      *
  137.      * @var     float
  138.      * @access  private
  139.      * @see     getField()
  140.      */
  141.     var $charge;
  142.  
  143.     /**
  144.      * If the atom object has been initialized
  145.      *
  146.      * @var     boolean
  147.      * @access  public
  148.      * @see     initAtom()
  149.      */
  150.     var $VALID = false;
  151.  
  152.     /**
  153.      * Reference to the containing Residue object
  154.      *
  155.      * @var     object  Residue_PDB
  156.      * @access  public
  157.      */
  158.     var $parent_residue;
  159.  
  160.     
  161.     function Science_Chemistry_Atom_PDB($atomrec, $residue="") {
  162.         // reference to containing residue
  163.         if (!empty($residue))
  164.             $this->parent_residue =& $residue;
  165.         // process PDB atom record
  166.         // no error checking, assumes correct and standard record
  167.         $this->VALID = true;
  168.         $this->rec_name = trim(substr($atomrec,0,6));
  169.         $this->ser_num = (int) trim(substr($atomrec,6,5));
  170.         $this->atom_name = trim(substr($atomrec,12,4));
  171.         $this->alt_loc = trim(substr($atomrec,16,1));
  172.         $this->res_name = trim(substr($atomrec,17,3));
  173.         $this->chain_id = trim(substr($atomrec,21,1));
  174.         $this->res_seq_num = (int) trim(substr($atomrec,22,4));
  175.         $this->ins_code = trim(substr($atomrec,26,1));
  176.         $this->occupancy = (float) trim(substr($atomrec,54,6));
  177.         $this->temp_factor = (float) trim(substr($atomrec,60,6));
  178.         $this->segment_id = trim(substr($atomrec,72,4));
  179.         $this->charge = (float)trim(substr($atomrec,78,2));
  180.         $x = (double) trim(substr($atomrec,30,8));
  181.         $y = (double) trim(substr($atomrec,38,8));
  182.         $z = (double) trim(substr($atomrec,46,8));
  183.         $this->xyz = new Science_Chemistry_Coordinates(array($x, $y, $z));
  184.         $element = trim(substr($atomrec,76,2));
  185.         // if no element is present, use the atom_name
  186.         $this->element = (preg_match('/^[A-Z]{1,2}/', $element)) ? $element : $this->atom_name;
  187.     }
  188.  
  189.     function getField($field) {
  190.         // mapping needed so we follow both the PEAR
  191.         // variable naming convention, and the PDB
  192.         // standard field naming convention
  193.         $map = array (
  194.                     "RecName"       => "rec_name",
  195.                     "SerNum"        => "ser_num",
  196.                     "AtomName"      => "atom_name",
  197.                     "AltLoc"        => "alt_loc",
  198.                     "ResName"       => "res_name",
  199.                     "ChainID"       => "chain_id",
  200.                     "ResSeqNum"     => "res_seq_num",
  201.                     "InsCode"       => "ins_code",
  202.                     "Ocuppancy"     => "ocuppancy",
  203.                     "TempFactor"    => "temp_factor",
  204.                     "SegmentID"     => "segment_id",
  205.                     "Charge"        => "charge",
  206.                     "Element"       => "element"
  207.                 );
  208.         // for coordinates index mapping
  209.         $cmap = array ("X"=>0, "Y"=>1, "Z"=>2);
  210.  
  211.         if (in_array($field, array_keys($map))) {
  212.             $internal_name = $map[$field];
  213.             return $this->$internal_name;
  214.         } elseif (in_array(strtoupper($field), array_keys($cmap))) {
  215.             $index = $cmap[strtoupper($field)];
  216.             return $this->xyz->coords[$index];
  217.         } else {
  218.             return null;
  219.         }
  220.     }
  221. }
  222.  
  223. // vim: expandtab: ts=4: sw=4
  224. ?>
  225.