Source for file PDBParser.php
Documentation is available at PDBParser.php
// +----------------------------------------------------------------------+
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license, |
// | that is bundled with this package in the file LICENSE, and is |
// | available at through the world-wide-web at |
// | http://www.php.net/license/2_02.txt. |
// | If you did not receive a copy of the PHP license and are unable to |
// | obtain it through the world-wide-web, please send a note to |
// | license@php.net so we can mail you a copy immediately. |
// +----------------------------------------------------------------------+
// | Authors: Jesus M. Castagnetto <jmcastagnetto@php.net> |
// +----------------------------------------------------------------------+
* A self-contained class to parse a PDB file into an array of residues
* each containing an array of atoms
* Useful when dealing with big PDB files, where using the Science_Chemistry_PDBFile
* class will generate out of memory errors.
* @author Jesus M. Castagnetto <jmcastagnetto@php.net>
* @package Science_Chemistry
* @see Science_Chemistry_PDBFile
* PDB macromolecule(s) class
* Array of macromolecules
* Number of macromolecules
* Constructor for the class, requires a PDB filename
* @param string $filename PDB filename
* @param boolean $multi whether to parse all models in a multi-model file
* @param boolean $meta whether to store the PDB file meta information
* @param boolean $full whether to store the full set of fields per atom
* @return object PDBParser
"JAN" => "01", "FEB" => "02", "MAR" => "03",
"APR" => "04", "MAY" => "05", "JUN" => "06",
"JUL" => "07", "AUG" => "08", "SEP" => "09",
"OCT" => "10", "NOV" => "11", "DEC" => "12"
$header_re = "/^HEADER[[:space:]]+(([^[:space:]]+ )+)[[:space:]]+";
$header_re .= "([0-9]{2}-[A-Z]{3}-[0-9]{2,4})[[:space:]]+[A-Z0-9]{4}/";
$this->class = trim($regs[1 ]);
// put date in a more standard format
$year = 2000 + (int) $tmp[2 ];
$year = 1900 + (int) $tmp[2 ];
$this->date = $year. "-". $month[$tmp[1 ]]. "-". $tmp[0 ];
for ($i=0; $i < count($arr); $i++ ) {
$rectype = strtok($arr[$i]," ");
// check if we have multi-model file
// did we get a multi-model file and are parsing the end
// of a model, if so, end parsing altogether
if ($rectype == "ENDMDL") {
$this->num_macromolecules++; // = count($this->macromolecules);
// accumulate atom records, put the rest into the meta array
if ($rectype == "ATOM" || $rectype == "HETATM")
$this->meta[$rectype][] = $arr[$i];
$this->num_macromolecules++; // = count($this->macromolecules);
* Makes the array of residues in the macromolecule
* @param boolean $full whether to store the full set of fields per atom
for ($i=0; $i< count($records); $i++ ) {
$atomrec = & $records[$i];
$res_id = $res_name. ":". $seq_num. ":". $chain;
// $curr_res_id = $res_id;
if ($res_id == $curr_res_id) {
if ($i != (count($records) - 1 ))
if (($res_id != $curr_res_id) ||
($i == (count($records) - 1 ))
if (!empty ($res_atoms)) {
for ($j=0; $j < count($res_atoms); $j++ ) {
$temp = $this->parseAtom($res_atoms[$j], $full, $atomname);
$residues[$curr_res_id][$atomname] = $temp;
$res_atoms = array ($atomrec);
* Parses an atom record into an associative array
* @param string $atomrec PDB atom record
* @param boolean $full whether to store the full set of fields per atom
function parseAtom($atomrec, $full, $atomname) {
// process PDB atom record
// no error checking, assumes correct and standard record
$atom["SerNum"] = (int) trim(substr($atomrec,6 ,5 ));
$atomname = $atom["AtomName"];
$atom["ResSeqNum"] = (int) trim(substr($atomrec,22 ,4 ));
$atom["Occupancy"] = (float) trim(substr($atomrec,54 ,6 ));
$atom["TempFactor"] = (float) trim(substr($atomrec,60 ,6 ));
$atom["Charge"] = (float) trim(substr($atomrec,78 ,2 ));
$atom["X"] = (double) trim(substr($atomrec,30 ,8 ));
$atom["Y"] = (double) trim(substr($atomrec,38 ,8 ));
$atom["Z"] = (double) trim(substr($atomrec,46 ,8 ));
* Returns an array of residues with a particular name
* from the indicated macromolecule index
* @param integer $macromol Index of the macromolecule in the $macromolecules array
* @param string $resnam Residue name, e.g. HIS, CYS, etc.
* @return array list of residues with the requested name
$mol = & $this->macromolecules[$macromol];
foreach($mol as $resid=> $atoms) {
list ($curr_res_name,,) = explode(":",$resid);
// echo $curr_res_name."***\n";
if ($curr_res_name == $resname)
$reslist[$resid] = $atoms;
// vim: expandtab: ts=4: sw=4
Documentation generated on Mon, 11 Mar 2019 15:48:16 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|