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

Source for file PDBFile.php

Documentation is available at PDBFile.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/Macromolecule_PDB.php";
  23.  
  24. /**
  25.  * Represents a PDB file, composed of one or more Science_Chemistry_Macromolecule_PDB objects
  26.  *
  27.  * @author  Jesus M. Castagnetto <jmcastagnetto@php.net>
  28.  * @version 1.0
  29.  * @access  public
  30.  * @package Science_Chemistry
  31.  * @see     Science_Chemistry_PDBParser
  32.  */
  33.  
  34.     /**
  35.      * PDB ID
  36.      *
  37.      * @var     string 
  38.      * @access   private
  39.      */
  40.     var $pdb;
  41.  
  42.     /**
  43.      * Full path to PDB file
  44.      *
  45.      * @var     string 
  46.      * @access  private
  47.      */
  48.     var $file;
  49.  
  50.     /**
  51.      * PDB file's date
  52.      *
  53.      * @var     string 
  54.      * @access  private
  55.      */
  56.     var $date;
  57.  
  58.     /**
  59.      * PDB macromolecule(s) class
  60.      *
  61.      * @var     string 
  62.      * @access  private
  63.      */
  64.     var $class;
  65.  
  66.     /**
  67.      * Array of meta records
  68.      *
  69.      * @var     array 
  70.      * @access  private
  71.      */
  72.     var $meta;
  73.  
  74.     /**
  75.      * Array of macromolecular objects
  76.      *
  77.      * @var     array 
  78.      * @access  private
  79.      */
  80.     var $macromolecules;
  81.  
  82.     /**
  83.      * Number of molecules/subunits
  84.      *
  85.      * @var     int 
  86.      * @access  private
  87.      */
  88.     var $num_macromolecules;
  89.  
  90.     /**
  91.      * Constructor for the class, requires a PDB filename
  92.      * 
  93.      * @param   string  $filename 
  94.      * @return  object  PDBFile; 
  95.      * @access  public
  96.      * @see     $pdb
  97.      * @see     $file
  98.      * @see     mkArrays()
  99.      */
  100.     function Science_Chemistry_PDBFile($filename$usemeta=false{
  101.         if (!file_exists($filename))
  102.             return null;
  103.         list($pdb,explode(".",basename($filename));
  104.         $this->pdb $pdb;
  105.         $this->file realpath($filename);
  106.         $this->parseFile(file($filename)$usemeta);
  107.     }
  108.  
  109.     /**
  110.      * Makes the arrays of all present PDB record types
  111.      *
  112.      * @param   array   $arr    array of lines
  113.      * @access  private
  114.      * @see     Science_Chemistry_Macromolecule_PDB()
  115.      */
  116.     function parseFile($arr$usemeta{
  117.         $month = array (
  118.                 "JAN" => "01""FEB" => "02""MAR" => "03",
  119.                 "APR" => "04""MAY" => "05""JUN" => "06",
  120.                 "JUL" => "07""AUG" => "08""SEP" => "09",
  121.                 "OCT" => "10""NOV" => "11""DEC" => "12"
  122.                 );
  123.         $header_re "/^HEADER[[:space:]]+(([^[:space:]]+ )+)[[:space:]]+";
  124.         $header_re .= "([0-9]{2}-[A-Z]{3}-[0-9]{2,4})[[:space:]]+[A-Z0-9]{4}/";
  125.  
  126.         if (preg_match($header_re$arr[0]$regs)) {
  127.             $this->class trim($regs[1]);
  128.             // put date in a more standard format
  129.             $tmp explode("-"$regs[3]);
  130.             if ($tmp[2<= 23)
  131.                 $year = 2000 + (int)$tmp[2];
  132.             else
  133.                 $year = 1900 + (int)$tmp[2];
  134.             $this->date $year."-".$month[$tmp[1]]."-".$tmp[0];
  135.         }
  136.         
  137.         $flag "nomodel";
  138.         $tmparr = array();
  139.         for ($i=0; $i count($arr)$i++{
  140.             if (!trim($arr[$i]))
  141.                 continue;
  142.             $rectype trim(strtok($arr[$i]," "));
  143.             
  144.             // check if we have multi-model file
  145.             if ($rectype == "MODEL"{
  146.                 $flag "model";
  147.                 continue;
  148.             }
  149.  
  150.             // create the meta array and accumulate the atom records
  151.             if ($rectype != "ATOM" && $rectype != "HETATM"{
  152.                 if ($usemeta{
  153.                     $this->meta[$rectype][trim($arr[$i]);
  154.                 else {
  155.                     continue;
  156.                 }
  157.             else {
  158.                 $tmparr[$arr[$i];
  159.             }
  160.  
  161.             // did we get a multi-model file and are parsing the end
  162.             // of a model, if so, create new macromolecule and change
  163.             // the flag
  164.             if ($rectype == "ENDMDL"{
  165.                 $this->macromolecules[= new Science_Chemistry_Macromolecule_PDB($this->pdb
  166.                                                 $tmparr$this);
  167.                 $this->num_macromolecules++;
  168.                 $flag "endmodel";
  169.                 $tmparr = array();
  170.             }
  171.         }
  172.         // if we got to the end without hitting a MODEL ... ENDMDL pair
  173.         // add the only macromolecule in this file to the array
  174.         if ($flag == "nomodel"{
  175.             $this->macromolecules[= new Science_Chemistry_Macromolecule_PDB($this->pdb
  176.                                             $tmparr$this);
  177.             $this->num_macromolecules++;
  178.         }
  179.     }
  180.  
  181.     /**
  182.      * Returns a CML representation of the PDB file
  183.      * TODO
  184.      *
  185.      * @return  string 
  186.      * @access  public
  187.      */
  188.     function toCML({
  189.         // TODO
  190.     }
  191.     
  192. // end of PDBFile
  193.  
  194. // vim: expandtab: ts=4: sw=4
  195. ?>

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