Source for file Molecule.php
Documentation is available at Molecule.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> |
// +----------------------------------------------------------------------+
require_once "Science/Chemistry.php";
require_once "Science/Chemistry/Atom.php";
* Base class representing a Molecule
* @author Jesus M. Castagnetto <jmcastagnetto@php.net>
* @package Science_Chemistry
* Number of atoms in the molecule
* Array of atom objects in the molecule
* Atom-Atom distance matrix
* @see calcDistanceMatrix()
var $dist_matrix = array ();
* Atom-Atom connection (bond) table
* @see calcConnectionTable()
var $conn_table = array ();
* Distance cutoff for bond estimation
* @see calcConnectionTable()
* Constructor for the class, requires a molecule name
* and an optional array of Science_Chemistry_Atom objects
* @param optional array $atoms
* @return object Science_Chemistry_Molecule
* Initializes the array of Science_Chemistry_Atom objects
for ($i=0; $i= count($atoms); $i++ ) {
* Adds a Science_Chemistry_Atom object to the list of atoms in the molecule
* @param object Science_Chemistry_Atom $atom
// 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 ();
* Returns an array of Atom objects
* Checks if the object is an instance of Science_Chemistry_Molecule
* @param object Science_Chemistry_Molecule $obj
* Returns a string representation of the molecule as a XYZ-format file
* Returns a string representation of the molecule as a XYZ-format file
$out[] = $this->atoms[$i]->toString ();
* Returns a CML representation of the molecule
* Accepts an optional id, and a flag to signal
* printing of the connection table
* @param optional string $id
* @param optional boolean $connect
function toCML($title= "molecule", $id= "mol1", $connect=false ) {
$out = " <molecule title=\"$title\" id=\"$id\">\n";
$out .= " <string title=\"name\">". $this->name. "</string>\n";
$out .= " <list title=\"atoms\">\n";
$out .= $this->atoms[$i]->toCML ($i+1 );
// calculate the connection table if needed
// and short-circuit if we cannot do that
if (empty ($this->conn_table))
$out .= " </molecule>\n";
$out .= " <list title=\"connections\">\n";
for ($i=0; $i < count($this->conn_table); $i++ ) {
foreach ($this->conn_table[$i] as $atomid=> $flag) {
$out .= " <list title=\"connect\" id=\"". ($i + 1 ). "\">";
$out .= implode(" ", $tmp). "</list>\n";
$out .= " </molecule>\n";
* Sets the distance cutoff for bond determination
* @see calcConnectionTable()
if ((float) $cutoff > 0.0 ) {
$this->BONDCUTOFF = (float) $cutoff;
* Returns the bond cutoff uses to determine bonds
* @see calcConnectionTable()
return $this->BONDCUTOFF;
* Calculates the atom-atom distance matrix in Angstroms
$this->dist_matrix = array ();
$this->dist_matrix[$i][$j] = 0.0;
$this->dist_matrix[$i][$j] = $this->atoms[$i]->distance ($this->atoms[$j]);
* Prints the atom-atom distance matrix
if (empty ($this->dist_matrix))
$dmat = &$this->dist_matrix;
echo "# Atom-Atom Distance Matrix:\n";
if (!isset ($dmat[$i][$j])) {
printf("\t%.4f",$dmat[$i][$j]);
* Returns the atom-atom distance matrix
if (empty ($this->dist_matrix))
return $this->dist_matrix;
* Calculates the connection table for the molecule
if (empty ($this->dist_matrix))
$dmat = &$this->dist_matrix;
$this->conn_table[$i][$j] = ($dmat[$i][$j] <= $this->BONDCUTOFF);
* Prints the molecule's connection table
if (empty ($this->conn_table))
printf("# Connection Table: (cutoff = %.4f Angstroms)\n", $this->BONDCUTOFF);
if ($this->conn_table[$i][$j]) {
echo $this->atoms[$i]->element. ($i+1 ). "\t";
echo $this->atoms[$j]->element. ($j+1 ). "\n";
* Returns an array of connected atoms and their bond distance
* e.g. array ( array ($atomobj1, $atomobj2, $distance ), ... )
if (empty ($this->conn_table))
$ct = 0; $ctable=array ();
if ($this->conn_table[$i][$j]) {
$ctable[$ct] = array ($this->atoms[$i], $this->atoms[$j],
$this->dist_matrix[$i][$j]);
} // end of class Science_Chemistry_Molecule
// 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.
|