Science_Chemistry
[ class tree: Science_Chemistry ] [ index: Science_Chemistry ] [ all elements ]

Source for file Atom_PDB.php

Documentation is available at Atom_PDB.php

  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$
  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.  
  34.     /**
  35.      * PDB Atom record type, one of ATOM or HETATM
  36.      *
  37.      * @var     string 
  38.      * @access  private
  39.      * @see     getField()
  40.      */
  41.     var $rec_name;
  42.  
  43.     /**
  44.      * PDB Atom serial number
  45.      *
  46.      * @var     integer 
  47.      * @access   private
  48.      * @see     getField()
  49.      */
  50.     var $ser_num;
  51.  
  52.     /**
  53.      * PDB Atom name
  54.      *
  55.      * @var     string 
  56.      * @access  private
  57.      * @see     getField()
  58.      */
  59.     var $atom_name;
  60.  
  61.     /**
  62.      * PDB Atom alternative location
  63.      *
  64.      * @var     string 
  65.      * @access  private
  66.      * @see     getField()
  67.      */
  68.     var $alt_loc;
  69.  
  70.     /**
  71.      * PDB Atom's Residue name
  72.      *
  73.      * @var     string 
  74.      * @access  private
  75.      * @see     getField()
  76.      */
  77.     var $res_name;
  78.  
  79.     /**
  80.      * PDB Atom's Residue chain ID
  81.      *
  82.      * @var     string 
  83.      * @access  private
  84.      * @see     getField()
  85.      */
  86.     var $chain_id;
  87.  
  88.     /**
  89.      * PDB Atom's Residue sequential numnber
  90.      *
  91.      * @var     string 
  92.      * @access  private
  93.      * @see     getField()
  94.      */
  95.     var $res_seq_num;
  96.  
  97.     /**
  98.      * PDB Atom insert code
  99.      *
  100.      * @var     string 
  101.      * @access  private
  102.      * @see     getField()
  103.      */
  104.     var $ins_code;
  105.  
  106.     /**
  107.      * PDB Atom occupancy
  108.      *
  109.      * @var     float 
  110.      * @access  private
  111.      * @see     getField()
  112.      */
  113.     var $occupancy;
  114.  
  115.     /**
  116.      * PDB Atom temperature factor
  117.      *
  118.      * @var     float 
  119.      * @access  private
  120.      * @see     getField()
  121.      */
  122.     var $temp_factor;
  123.  
  124.     /**
  125.      * PDB Atom segment identifier
  126.      *
  127.      * @var     string 
  128.      * @access  private
  129.      * @see     getField()
  130.      */
  131.     var $segment_id;
  132.  
  133.     /**
  134.      * PDB Atom electronic charge
  135.      *
  136.      * @var     float 
  137.      * @access  private
  138.      * @see     getField()
  139.      */
  140.     var $charge;
  141.  
  142.     /**
  143.      * If the atom object has been initialized
  144.      *
  145.      * @var     boolean 
  146.      * @access  public
  147.      * @see     initAtom()
  148.      */
  149.     var $VALID = false;
  150.  
  151.     /**
  152.      * Reference to the containing Residue object
  153.      *
  154.      * @var     object  Residue_PDB 
  155.      * @access  public
  156.      */
  157.     var $parent_residue;
  158.  
  159.     
  160.     function Science_Chemistry_Atom_PDB(&$atomrec&$residue=""{
  161.         // reference to containing residue
  162.         if (!empty($residue)) {
  163.             $this->parent_residue = $residue;
  164.         }
  165.  
  166.         // process PDB atom record
  167.         // no error checking, assumes correct and standard record
  168.         $this->VALID = true;
  169.         $this->rec_name trim(substr($atomrec,0,6));
  170.         $this->ser_num = (int) trim(substr($atomrec,6,5));
  171.         $this->atom_name trim(substr($atomrec,12,4));
  172.         $this->alt_loc trim(substr($atomrec,16,1));
  173.         $this->res_name trim(substr($atomrec,17,3));
  174.         $this->chain_id trim(substr($atomrec,21,1));
  175.         $this->res_seq_num = (int) trim(substr($atomrec,22,4));
  176.         $this->ins_code trim(substr($atomrec,26,1));
  177.         $this->occupancy = (float) trim(substr($atomrec,54,6));
  178.         $this->temp_factor = (float) trim(substr($atomrec,60,6));
  179.         $this->segment_id trim(substr($atomrec,72,4));
  180.         $this->charge = (float)trim(substr($atomrec,78,2));
  181.         $x = (double) trim(substr($atomrec,30,8));
  182.         $y = (double) trim(substr($atomrec,38,8));
  183.         $z = (double) trim(substr($atomrec,46,8));
  184.         $this->xyz = new Science_Chemistry_Coordinates(array($x$y$z));
  185.         $element trim(substr($atomrec,76,2));
  186.         // if no element is present, use the atom_name
  187.         $this->element (preg_match('/^[A-Z]{1,2}/'$element)) $element $this->atom_name;
  188.     }
  189.  
  190.     function getField($field{
  191.         // mapping needed so we follow both the PEAR
  192.         // variable naming convention, and the PDB
  193.         // standard field naming convention
  194.         $map = array (
  195.                     "RecName"       => "rec_name",
  196.                     "SerNum"        => "ser_num",
  197.                     "AtomName"      => "atom_name",
  198.                     "AltLoc"        => "alt_loc",
  199.                     "ResName"       => "res_name",
  200.                     "ChainID"       => "chain_id",
  201.                     "ResSeqNum"     => "res_seq_num",
  202.                     "InsCode"       => "ins_code",
  203.                     "Ocuppancy"     => "ocuppancy",
  204.                     "TempFactor"    => "temp_factor",
  205.                     "SegmentID"     => "segment_id",
  206.                     "Charge"        => "charge",
  207.                     "Element"       => "element"
  208.                 );
  209.         // for coordinates index mapping
  210.         $cmap = array ("X"=>0"Y"=>1"Z"=>2);
  211.  
  212.         if (in_array($fieldarray_keys($map))) {
  213.             $internal_name $map[$field];
  214.             return $this->$internal_name;
  215.         elseif (in_array(strtoupper($field)array_keys($cmap))) {
  216.             $index $cmap[strtoupper($field)];
  217.             return $this->xyz->coords[$index];
  218.         else {
  219.             return null;
  220.         }
  221.     }
  222. }
  223.  
  224. // vim: expandtab: ts=4: sw=4
  225. ?>

Documentation generated on Mon, 11 Mar 2019 15:48:15 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.