示例#1
0
 /**
  * Adds a Science_Chemistry_Atom object to the list of atoms in the molecule
  * 
  * @param   object  Science_Chemistry_Atom   $atom
  * @return  boolean
  * @access  public
  * @see     initMolecule()
  */
 function addAtom($atom)
 {
     if (Science_Chemistry_Atom::isAtom($atom)) {
         $this->atoms[] = $atom;
         $this->num_atoms++;
         // unset the distance matrix and
         // connection table if they are not empty
         // so next time either one is requested
         // it gets calculated anew
         if (!empty($this->dist_matrix)) {
             $this->dist_matrix = array();
         }
         if (!empty($this->conn_table)) {
             $this->conn_table = array();
         }
         return true;
     } else {
         return false;
     }
 }
示例#2
0
// | 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 <*****@*****.**>                |
// +----------------------------------------------------------------------+
//
// $Id: testChem.php,v 1.3 2003/01/04 11:56:25 mj Exp $
//
require_once "Science/Chemistry.php";
require_once "Science/Chemistry/Molecule_XYZ.php";
require_once "Science/Chemistry/Macromolecule.php";
echo "Creating and printing an atom\n";
$a = new Science_Chemistry_Atom("N", array(2.3, 4.5, -2.1));
echo $a->toString() . "\n";
echo "Creating a second atom and calculating distance to first one\n";
$b = new Science_Chemistry_Atom("C", array(1.2, 3.4, -1.6));
echo $b->toString() . "\n";
echo "\nDistance N to C: " . sprintf("%.4f", $a->distance($b)) . " Angstroms\n";
//print_r($a);
//print_r($b);
echo "\n=====\nReading a molecule:\n";
$m = new Science_Chemistry_Molecule_XYZ("his.xyz");
echo "\$m is a molecule: " . (int) Science_Chemistry_Molecule::isMolecule($m) . "\n";
echo $m->toString();
//echo "Calculating Distance Matrix\n";
//$m->printDistanceMatrix();
//echo "Calculating Connection Table\n";
//$m->printConnectionTable();
 /**
  * Calculates the cartesian distance from this atom
  * instance to another
  *
  * @param   object  Science_Chemistry_Atom $atom2
  * @return  float   distance
  * @access  public
  */
 function distance($atom2)
 {
     if (!empty($this->xyz) && Science_Chemistry_Coordinates::areCoordinates($this->xyz) && Science_Chemistry_Atom::isAtom($atom2)) {
         return $this->xyz->distance($atom2->xyz);
     } else {
         return -1.0;
     }
 }