From: <sh...@us...> - 2010-03-25 14:29:51
|
Revision: 15495 http://cdk.svn.sourceforge.net/cdk/?rev=15495&view=rev Author: shk3 Date: 2010-03-25 14:29:42 +0000 (Thu, 25 Mar 2010) Log Message: ----------- Some speedups. Notice classes from data and interfaces package of cdk are now in since they were changed for faster handling of getConnectedAtoms. I have no idea how this could go into cdk. Modified Paths: -------------- detgen/trunk/src/org/openscience/cdk/structgen/deterministic/DeterministicGenerator.java Added Paths: ----------- detgen/trunk/src/org/openscience/cdk/AminoAcid.java detgen/trunk/src/org/openscience/cdk/Association.java detgen/trunk/src/org/openscience/cdk/Atom.java detgen/trunk/src/org/openscience/cdk/AtomContainer.java detgen/trunk/src/org/openscience/cdk/AtomContainerSet.java detgen/trunk/src/org/openscience/cdk/AtomParity.java detgen/trunk/src/org/openscience/cdk/AtomType.java detgen/trunk/src/org/openscience/cdk/BioPolymer.java detgen/trunk/src/org/openscience/cdk/Bond.java detgen/trunk/src/org/openscience/cdk/CDKConstants.java detgen/trunk/src/org/openscience/cdk/ChemFile.java detgen/trunk/src/org/openscience/cdk/ChemModel.java detgen/trunk/src/org/openscience/cdk/ChemObject.java detgen/trunk/src/org/openscience/cdk/ChemSequence.java detgen/trunk/src/org/openscience/cdk/ConformerContainer.java detgen/trunk/src/org/openscience/cdk/Crystal.java detgen/trunk/src/org/openscience/cdk/DefaultChemObjectBuilder.java detgen/trunk/src/org/openscience/cdk/ElectronContainer.java detgen/trunk/src/org/openscience/cdk/Element.java detgen/trunk/src/org/openscience/cdk/EnzymeResidueLocator.java detgen/trunk/src/org/openscience/cdk/FragmentAtom.java detgen/trunk/src/org/openscience/cdk/IImplementationSpecification.java detgen/trunk/src/org/openscience/cdk/Isotope.java detgen/trunk/src/org/openscience/cdk/LonePair.java detgen/trunk/src/org/openscience/cdk/Mapping.java detgen/trunk/src/org/openscience/cdk/Molecule.java detgen/trunk/src/org/openscience/cdk/MoleculeSet.java detgen/trunk/src/org/openscience/cdk/Monomer.java detgen/trunk/src/org/openscience/cdk/PhysicalConstants.java detgen/trunk/src/org/openscience/cdk/Polymer.java detgen/trunk/src/org/openscience/cdk/PseudoAtom.java detgen/trunk/src/org/openscience/cdk/Reaction.java detgen/trunk/src/org/openscience/cdk/ReactionScheme.java detgen/trunk/src/org/openscience/cdk/ReactionSet.java detgen/trunk/src/org/openscience/cdk/Ring.java detgen/trunk/src/org/openscience/cdk/RingSet.java detgen/trunk/src/org/openscience/cdk/SingleElectron.java detgen/trunk/src/org/openscience/cdk/Strand.java detgen/trunk/src/org/openscience/cdk/Vibration.java detgen/trunk/src/org/openscience/cdk/event/ detgen/trunk/src/org/openscience/cdk/event/ChemObjectChangeEvent.java detgen/trunk/src/org/openscience/cdk/event/ICDKChangeListener.java detgen/trunk/src/org/openscience/cdk/formula/ detgen/trunk/src/org/openscience/cdk/formula/AdductFormula.java detgen/trunk/src/org/openscience/cdk/formula/MolecularFormula.java detgen/trunk/src/org/openscience/cdk/formula/MolecularFormulaSet.java detgen/trunk/src/org/openscience/cdk/graph/ detgen/trunk/src/org/openscience/cdk/graph/matrix/ detgen/trunk/src/org/openscience/cdk/graph/matrix/IGraphMatrix.java detgen/trunk/src/org/openscience/cdk/interfaces/ detgen/trunk/src/org/openscience/cdk/interfaces/IAdductFormula.java detgen/trunk/src/org/openscience/cdk/interfaces/IAminoAcid.java detgen/trunk/src/org/openscience/cdk/interfaces/IAtom.java detgen/trunk/src/org/openscience/cdk/interfaces/IAtomContainer.java detgen/trunk/src/org/openscience/cdk/interfaces/IAtomContainerSet.java detgen/trunk/src/org/openscience/cdk/interfaces/IAtomParity.java detgen/trunk/src/org/openscience/cdk/interfaces/IAtomType.java detgen/trunk/src/org/openscience/cdk/interfaces/IBioPolymer.java detgen/trunk/src/org/openscience/cdk/interfaces/IBond.java detgen/trunk/src/org/openscience/cdk/interfaces/IChemFile.java detgen/trunk/src/org/openscience/cdk/interfaces/IChemModel.java detgen/trunk/src/org/openscience/cdk/interfaces/IChemObject.java detgen/trunk/src/org/openscience/cdk/interfaces/IChemObjectBuilder.java detgen/trunk/src/org/openscience/cdk/interfaces/IChemObjectChangeEvent.java detgen/trunk/src/org/openscience/cdk/interfaces/IChemObjectListener.java detgen/trunk/src/org/openscience/cdk/interfaces/IChemSequence.java detgen/trunk/src/org/openscience/cdk/interfaces/ICrystal.java detgen/trunk/src/org/openscience/cdk/interfaces/IElectronContainer.java detgen/trunk/src/org/openscience/cdk/interfaces/IElement.java detgen/trunk/src/org/openscience/cdk/interfaces/IFragmentAtom.java detgen/trunk/src/org/openscience/cdk/interfaces/IIsotope.java detgen/trunk/src/org/openscience/cdk/interfaces/ILonePair.java detgen/trunk/src/org/openscience/cdk/interfaces/IMapping.java detgen/trunk/src/org/openscience/cdk/interfaces/IMolecularFormula.java detgen/trunk/src/org/openscience/cdk/interfaces/IMolecularFormulaSet.java detgen/trunk/src/org/openscience/cdk/interfaces/IMolecule.java detgen/trunk/src/org/openscience/cdk/interfaces/IMoleculeSet.java detgen/trunk/src/org/openscience/cdk/interfaces/IMonomer.java detgen/trunk/src/org/openscience/cdk/interfaces/IPDBAtom.java detgen/trunk/src/org/openscience/cdk/interfaces/IPDBMonomer.java detgen/trunk/src/org/openscience/cdk/interfaces/IPDBPolymer.java detgen/trunk/src/org/openscience/cdk/interfaces/IPDBStructure.java detgen/trunk/src/org/openscience/cdk/interfaces/IPolymer.java detgen/trunk/src/org/openscience/cdk/interfaces/IPseudoAtom.java detgen/trunk/src/org/openscience/cdk/interfaces/IReaction.java detgen/trunk/src/org/openscience/cdk/interfaces/IReactionScheme.java detgen/trunk/src/org/openscience/cdk/interfaces/IReactionSet.java detgen/trunk/src/org/openscience/cdk/interfaces/IRing.java detgen/trunk/src/org/openscience/cdk/interfaces/IRingSet.java detgen/trunk/src/org/openscience/cdk/interfaces/ISingleElectron.java detgen/trunk/src/org/openscience/cdk/interfaces/IStrand.java detgen/trunk/src/org/openscience/cdk/isomorphism/ detgen/trunk/src/org/openscience/cdk/isomorphism/matchers/ detgen/trunk/src/org/openscience/cdk/isomorphism/matchers/IQueryAtom.java detgen/trunk/src/org/openscience/cdk/isomorphism/matchers/IQueryAtomContainer.java detgen/trunk/src/org/openscience/cdk/isomorphism/matchers/IQueryBond.java detgen/trunk/src/org/openscience/cdk/protein/ detgen/trunk/src/org/openscience/cdk/protein/data/ detgen/trunk/src/org/openscience/cdk/protein/data/PDBAtom.java detgen/trunk/src/org/openscience/cdk/protein/data/PDBMonomer.java detgen/trunk/src/org/openscience/cdk/protein/data/PDBPolymer.java detgen/trunk/src/org/openscience/cdk/protein/data/PDBStrand.java detgen/trunk/src/org/openscience/cdk/protein/data/PDBStructure.java detgen/trunk/src/org/openscience/cdk/renderer/ detgen/trunk/src/org/openscience/cdk/renderer/color/ detgen/trunk/src/org/openscience/cdk/renderer/color/IAtomColorer.java Added: detgen/trunk/src/org/openscience/cdk/AminoAcid.java =================================================================== --- detgen/trunk/src/org/openscience/cdk/AminoAcid.java (rev 0) +++ detgen/trunk/src/org/openscience/cdk/AminoAcid.java 2010-03-25 14:29:42 UTC (rev 15495) @@ -0,0 +1,167 @@ +/* $Revision$ $Author$ $Date$ + * + * Copyright (C) 2005-2007 Egon Willighagen <e.w...@sc...> + * + * Contact: cdk...@li... + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * All we ask is that proper credit is given for our work, which includes + * - but is not limited to - adding the above copyright notice to the beginning + * of your source code files, and to any copyright notice that you may distribute + * with programs based on this work. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk; + +import java.io.Serializable; + +import org.openscience.cdk.interfaces.IAminoAcid; +import org.openscience.cdk.interfaces.IAtom; + +/** + * A AminoAcid is Monomer which stores additional amino acid specific + * informations, like the N-terminus atom. + * + * @cdk.module data + * @cdk.githash + * + * @author Egon Willighagen <e.w...@sc...> + * @cdk.created 2005-08-11 + * @cdk.keyword amino acid + */ +public class AminoAcid extends Monomer implements IAminoAcid, Serializable, Cloneable { + + /** + * Determines if a de-serialized object is compatible with this class. + * + * This value must only be changed if and only if the new version + * of this class is incompatible with the old version. See Sun docs + * for <a href=http://java.sun.com/products/jdk/1.1/docs/guide + * /serialization/spec/version.doc.html>details</a>. + */ + private static final long serialVersionUID = -5032283549467862509L; + + /** The atom that constitutes the N-terminus. */ + private IAtom nTerminus; + /** The atom that constitutes the C-terminus. */ + private IAtom cTerminus; + + /** + * Constructs a new AminoAcid. + */ + public AminoAcid() { + super(); + } + + /** + * Retrieves the N-terminus atom. + * + * @return The Atom that is the N-terminus + * + * @see #addNTerminus(IAtom) + */ + public IAtom getNTerminus() { + return nTerminus; + } + + /** + * Add an Atom and makes it the N-terminus atom. + * + * @param atom The Atom that is the N-terminus + * + * @see #getNTerminus + */ + public void addNTerminus(IAtom atom) { + super.addAtom(atom); + nTerminus = atom; + } + + /** + * Marks an Atom as being the N-terminus atom. It assumes that the Atom + * is already added to the AminoAcid. + * + * @param atom The Atom that is the N-terminus + * + * @see #addNTerminus + */ + private void setNTerminus(IAtom atom) { + nTerminus = atom; + } + + /** + * Retrieves the C-terminus atom. + * + * @return The Atom that is the C-terminus + * + * @see #addCTerminus(IAtom) + */ + public IAtom getCTerminus() { + return cTerminus; + } + + /** + * Add an Atom and makes it the C-terminus atom. + * + * @param atom The Atom that is the C-terminus + * + * @see #getCTerminus + */ + public void addCTerminus(IAtom atom) { + super.addAtom(atom); + setCTerminus(atom); + } + + /** + * Marks an Atom as being the C-terminus atom. It assumes that the Atom + * is already added to the AminoAcid. + * + * @param atom The Atom that is the C-terminus + * + * @see #addCTerminus + */ + private void setCTerminus(IAtom atom) { + cTerminus = atom; + } + + /** + * Clones this AminoAcid object. + * + * @return The cloned object + */ + public Object clone() throws CloneNotSupportedException { + AminoAcid clone = (AminoAcid) super.clone(); + // copying the new N-terminus and C-terminus pointers + if (getNTerminus() != null) + clone.setNTerminus(clone.getAtom(getAtomNumber(getNTerminus()))); + if (getCTerminus() != null) + clone.setCTerminus(clone.getAtom(getAtomNumber(getCTerminus()))); + return clone; + } + + public String toString() { + StringBuffer stringContent = new StringBuffer(32); + stringContent.append("AminoAcid("); + stringContent.append(this.hashCode()); + if (nTerminus != null) { + stringContent.append(", N:").append(nTerminus.toString()); + } + if (cTerminus != null) { + stringContent.append(", C:").append(cTerminus.toString()); + } + stringContent.append(", ").append(super.toString()); + stringContent.append(')'); + return stringContent.toString(); + } + +} Added: detgen/trunk/src/org/openscience/cdk/Association.java =================================================================== --- detgen/trunk/src/org/openscience/cdk/Association.java (rev 0) +++ detgen/trunk/src/org/openscience/cdk/Association.java 2010-03-25 14:29:42 UTC (rev 15495) @@ -0,0 +1,194 @@ +/* $Revision$ $Author$ $Date$ + * + * Copyright (C) 2004-2007 Egon Willighagen <eg...@us...> + * + * Contact: cdk...@li... + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk; + +import org.openscience.cdk.annotations.TestClass; +import org.openscience.cdk.annotations.TestMethod; +import org.openscience.cdk.interfaces.IAtom; + +/** + * Base class for storing interactions like hydrogen bonds and ionic interactions. + * The ElectronContainer contains zero electrons by default. + * + * @cdk.module extra + * @cdk.githash + * + * @cdk.keyword orbital + * @cdk.keyword association + * @cdk.keyword bond + */ +@TestClass("org.openscience.cdk.AssociationTest") +public class Association extends ElectronContainer implements java.io.Serializable, Cloneable { + + /** + * Determines if a de-serialized object is compatible with this class. + * + * This value must only be changed if and only if the new version + * of this class is incompatible with the old version. See Sun docs + * for <a href=http://java.sun.com/products/jdk/1.1/docs/guide + * /serialization/spec/version.doc.html>details</a>. + */ + private static final long serialVersionUID = -9138919895942850167L; + + /** Number of electrons in the association. */ + protected final int electronCount = 0; + + /** The atoms which take part in the association. */ + protected IAtom[] atoms; + protected int atomCount; + + /** + * Constructs an association between two Atom's. + * + * @param atom1 An atom to be associated with another atom + * @param atom2 An atom to be associated with another atom + * @see org.openscience.cdk.Atom + */ + @TestMethod("testAssociation_IAtom_IAtom") + public Association(IAtom atom1, IAtom atom2) { + atoms = new IAtom[2]; + atoms[0] = atom1; + atoms[1] = atom2; + atomCount = 2; + } + + /** + * Constructs an empty association. + * + * @see org.openscience.cdk.Atom + */ + @TestMethod("testAssociation") + public Association() { + atoms = new Atom[2]; + atomCount = 0; + } + + /** + * Returns the array of atoms making up this Association. + * + * @return An array of atoms participating in this Association + * + * @see #setAtoms + */ + @TestMethod("testGetAtoms") + public IAtom[] getAtoms() { + IAtom[] returnAtoms = new Atom[atomCount]; + System.arraycopy(this.atoms, 0, returnAtoms, 0, returnAtoms.length); + return returnAtoms; + } + + /** + * Sets the array of atoms making up this Association. + * + * @param atoms An array of atoms that forms this Association + * + * @see #getAtoms + */ + @TestMethod("testSetAtoms") + public void setAtoms(IAtom[] atoms) { + this.atoms = atoms; + notifyChanged(); + } + + + /** + * Returns the number of Atoms in this Association. + * + * @return The number of Atoms in this Association + */ + @TestMethod("testGetAtomCount") + public int getAtomCount() { + return atomCount; + } + + /** + * Returns the number of electrons in a Association. + * + * @return The number of electrons in a Association. + */ + @TestMethod("testGetAtomAt") + public Integer getElectronCount() { + return 0; + } + + /** + * Returns an Atom from this Association. + * + * @param position The position in this bond where the atom is + * @return The atom at the specified position + * + * @see #setAtomAt + */ + @TestMethod("testGetAtomAt") + public IAtom getAtomAt(int position) { + return atoms[position]; + } + + /** + * Returns true if the given atom participates in this Association. + * + * @param atom The atom to be tested if it participates in this Association + * @return true if the atom participates in this Association + */ + @TestMethod("testContains") + public boolean contains(IAtom atom) { + for (IAtom atom1 : atoms) { + if (atom1 == atom) { + return true; + } + } + return false; + } + + /** + * Sets an Atom in this Association. + * + * @param atom The atom to be set + * @param position The position in this Association where the atom is to be inserted + * + * @see #getAtomAt + */ + @TestMethod("testSetAtomAt") + public void setAtomAt(IAtom atom, int position) { + atoms[position] = atom; + notifyChanged(); + } + + /** + * Returns a one line string representation of this Container. + * This method is conform RFC #9. + * + * @return The string representation of this Container + */ + @TestMethod("testToString") + public String toString() { + StringBuffer s = new StringBuffer(); + s.append("Association("); + s.append(this.hashCode()); + for (int i=0; i<atomCount; i++) { + s.append(", ").append(atoms[i].toString()); + } + s.append(")"); + return s.toString(); + } +} + + Property changes on: detgen/trunk/src/org/openscience/cdk/Association.java ___________________________________________________________________ Added: svn:executable + * Added: detgen/trunk/src/org/openscience/cdk/Atom.java =================================================================== --- detgen/trunk/src/org/openscience/cdk/Atom.java (rev 0) +++ detgen/trunk/src/org/openscience/cdk/Atom.java 2010-03-25 14:29:42 UTC (rev 15495) @@ -0,0 +1,430 @@ +/* $Revision$ $Author$ $Date$ + * + * Copyright (C) 2000-2007 Christoph Steinbeck <ste...@us...> + * + * Contact: cdk...@li... + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * All we ask is that proper credit is given for our work, which includes + * - but is not limited to - adding the above copyright notice to the beginning + * of your source code files, and to any copyright notice that you may distribute + * with programs based on this work. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import javax.vecmath.Point2d; +import javax.vecmath.Point3d; + +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IElement; + +/** + * Represents the idea of an chemical atom. + * + * <p>An Atom class is instantiated with at least the atom symbol: + * <pre> + * Atom a = new Atom("C"); + * </pre> + * + * <p>Once instantiated all field not filled by passing parameters + * to the constructor are null. Atoms can be configured by using + * the IsotopeFactory.configure() method: + * <pre> + * IsotopeFactory if = IsotopeFactory.getInstance(a.getBuilder()); + * if.configure(a); + * </pre> + * + * <p>More examples about using this class can be found in the + * Junit test for this class. + * + * @cdk.module data + * @cdk.githash + * + * @author steinbeck + * @cdk.created 2000-10-02 + * @cdk.keyword atom + * + * @see org.openscience.cdk.config.IsotopeFactory#getInstance(org.openscience.cdk.interfaces.IChemObjectBuilder) + */ +public class Atom extends AtomType implements IAtom, Serializable, Cloneable { + + /* Let's keep this exact specification + * of what kind of point2d we're talking of here, + * since there are so many around in the java standard api */ + + /** + * Determines if a de-serialized object is compatible with this class. + * + * This value must only be changed if and only if the new version + * of this class is incompatible with the old version. See Sun docs + * for <a href=http://java.sun.com/products/jdk/1.1/docs/guide + * /serialization/spec/version.doc.html>details</a>. + */ + private static final long serialVersionUID = -3137373012494608794L; + + /** + * A 2D point specifying the location of this atom in a 2D coordinate + * space. + */ + protected javax.vecmath.Point2d point2d = (Point2d) CDKConstants.UNSET; + /** + * A 3 point specifying the location of this atom in a 3D coordinate + * space. + */ + protected javax.vecmath.Point3d point3d = (Point3d) CDKConstants.UNSET; + /** + * A 3 point specifying the location of this atom in a crystal unit cell. + */ + protected javax.vecmath.Point3d fractionalPoint3d = (Point3d) CDKConstants.UNSET; + /** + * The number of implicitly bound hydrogen atoms for this atom. + */ + protected Integer hydrogenCount = (Integer) CDKConstants.UNSET; + /** + * A stereo parity descriptor for the stereochemistry of this atom. + */ + protected Integer stereoParity = (Integer) CDKConstants.UNSET; + /** + * The partial charge of the atom. + * + * The default value is {@link CDKConstants#UNSET} and serves to provide a check whether the charge has been + * set or not + */ + protected Double charge = (Double) CDKConstants.UNSET; + + private List<IAtom> connectedAtomsList = new ArrayList<IAtom>(); + + /** + * Constructs an completely unset Atom. + */ + public Atom() { + super((String)null); + } + + /** + * Constructs an Atom from a String containing an element symbol. + * + * @param elementSymbol The String describing the element for the Atom + */ + public Atom(String elementSymbol) { + super(elementSymbol); + } + + /** + * Constructs an Atom from an Element and a Point3d. + * + * @param elementSymbol The symbol of the atom + * @param point3d The 3D coordinates of the atom + */ + public Atom(String elementSymbol, javax.vecmath.Point3d point3d) + { + this(elementSymbol); + this.point3d = point3d; + } + + /** + * Constructs an Atom from an Element and a Point2d. + * + * @param elementSymbol The Element + * @param point2d The Point + */ + public Atom(String elementSymbol, javax.vecmath.Point2d point2d) + { + this(elementSymbol); + this.point2d = point2d; + } + + /** + * Constructs an isotope by copying the symbol, atomic number, + * flags, identifier, exact mass, natural abundance, mass + * number, maximum bond order, bond order sum, van der Waals + * and covalent radii, formal charge, hybridization, electron + * valency, formal neighbour count and atom type name from the + * given IAtomType. It does not copy the listeners and + * properties. If the element is an instanceof + * IAtom, then the 2D, 3D and fractional coordinates, partial + * atomic charge, hydrogen count and stereo parity are copied + * too. + * + * @param element IAtomType to copy information from + */ + public Atom(IElement element) { + super(element); + if (element instanceof IAtom) { + if (((IAtom)element).getPoint2d() != null) { + this.point2d = new Point2d(((IAtom)element).getPoint2d()); + } else { + this.point2d = null; + } + if (((IAtom)element).getPoint3d() != null) { + this.point3d = new Point3d(((IAtom)element).getPoint3d()); + } else { + this.point3d = null; + } + if (((IAtom)element).getFractionalPoint3d() != null) { + this.fractionalPoint3d = new Point3d(((IAtom)element).getFractionalPoint3d()); + } else { + this.fractionalPoint3d = null; + } + this.hydrogenCount = ((IAtom)element).getHydrogenCount(); + this.charge = ((IAtom)element).getCharge(); + this.stereoParity = ((IAtom)element).getStereoParity(); + } + } + + /** + * Sets the partial charge of this atom. + * + * @param charge The partial charge + * + * @see #getCharge + */ + public void setCharge(Double charge) { + this.charge = charge; + notifyChanged(); + } + + /** + * Returns the partial charge of this atom. + * + * If the charge has not been set the return value is Double.NaN + * + * @return the charge of this atom + * + * @see #setCharge + */ + public Double getCharge() { + return this.charge; + } + + /** + * Sets the number of implicit hydrogen count of this atom. + * + * @param hydrogenCount The number of hydrogen atoms bonded to this atom. + * + * @see #getHydrogenCount + */ + public void setHydrogenCount(Integer hydrogenCount) { + this.hydrogenCount = hydrogenCount; + notifyChanged(); + } + + /** + * Returns the hydrogen count of this atom. + * + * @return The hydrogen count of this atom. + * + * @see #setHydrogenCount + */ + public Integer getHydrogenCount() { + return this.hydrogenCount; + } + + /** + * + * Sets a point specifying the location of this + * atom in a 2D space. + * + * @param point2d A point in a 2D plane + * + * @see #getPoint2d + */ + public void setPoint2d(javax.vecmath.Point2d point2d) { + this.point2d = point2d; + notifyChanged(); + } + /** + * + * Sets a point specifying the location of this + * atom in 3D space. + * + * @param point3d A point in a 3-dimensional space + * + * @see #getPoint3d + */ + public void setPoint3d(javax.vecmath.Point3d point3d) { + this.point3d = point3d; + notifyChanged(); + } + /** + * Sets a point specifying the location of this + * atom in a Crystal unit cell. + * + * @param point3d A point in a 3d fractional unit cell space + * + * @see #getFractionalPoint3d + * @see org.openscience.cdk.Crystal + */ + public void setFractionalPoint3d(javax.vecmath.Point3d point3d) { + this.fractionalPoint3d = point3d; + notifyChanged(); + } + /** + * Sets the stereo parity for this atom. + * + * @param stereoParity The stereo parity for this atom + * + * @see org.openscience.cdk.CDKConstants for predefined values. + * @see #getStereoParity + */ + public void setStereoParity(Integer stereoParity) { + this.stereoParity = stereoParity; + notifyChanged(); + } + + /** + * Returns a point specifying the location of this + * atom in a 2D space. + * + * @return A point in a 2D plane. Null if unset. + * + * @see #setPoint2d + */ + public javax.vecmath.Point2d getPoint2d() { + return this.point2d; + } + /** + * Returns a point specifying the location of this + * atom in a 3D space. + * + * @return A point in 3-dimensional space. Null if unset. + * + * @see #setPoint3d + */ + public javax.vecmath.Point3d getPoint3d() { + return this.point3d; + } + + /** + * Returns a point specifying the location of this + * atom in a Crystal unit cell. + * + * @return A point in 3d fractional unit cell space. Null if unset. + * + * @see #setFractionalPoint3d + * @see org.openscience.cdk.CDKConstants for predefined values. + */ + public javax.vecmath.Point3d getFractionalPoint3d() { + return this.fractionalPoint3d; + } + + /** + * Returns the stereo parity of this atom. It uses the predefined values + * found in CDKConstants. + * + * @return The stereo parity for this atom + * + * @see org.openscience.cdk.CDKConstants + * @see #setStereoParity + */ + public Integer getStereoParity() { + return this.stereoParity; + } + + /** + * Compares a atom with this atom. + * + * @param object of type Atom + * @return true, if the atoms are equal + */ + public boolean compare(Object object) + { + if (!(object instanceof IAtom)) { + return false; + } + if (!super.compare(object)) { + return false; + } + Atom atom = (Atom) object; + if (((point2d==atom.point2d) || ((point2d!=null) && (point2d.equals(atom.point2d)))) && + ((point3d==atom.point3d) || ((point3d!=null) && (point3d.equals(atom.point3d)))) && + (hydrogenCount==atom.hydrogenCount) && + (stereoParity==atom.stereoParity) && + (charge==atom.charge)) { + return true; + } + return false; + } + + /** + * Returns a one line string representation of this Atom. + * Methods is conform RFC #9. + * + * @return The string representation of this Atom + */ + public String toString() { + StringBuffer stringContent = new StringBuffer(64); + stringContent.append("Atom(").append(hashCode()); + if (getSymbol() != null) { + stringContent.append(", S:").append(getSymbol()); + } + if (getHydrogenCount() != null) { + stringContent.append(", H:").append(getHydrogenCount()); + } + if (getStereoParity() != null) { + stringContent.append(", SP:").append(getStereoParity()); + } + if (getPoint2d() != null) { + stringContent.append(", 2D:[").append(getPoint2d()).append(']'); + } + if (getPoint3d() != null) { + stringContent.append(", 3D:[").append(getPoint3d()).append(']'); + } + if (getFractionalPoint3d() != null) { + stringContent.append(", F3D:[").append(getFractionalPoint3d()); + } + if (getCharge() != null) { + stringContent.append(", C:").append(getCharge()); + } + stringContent.append(", ").append(super.toString()); + stringContent.append(')'); + return stringContent.toString(); + } + + + /** + * Clones this atom object and its content. + * + * @return The cloned object + */ + public Object clone() throws CloneNotSupportedException { + Object clone = super.clone(); + if (point2d != null) { + ((Atom)clone).setPoint2d(new Point2d(point2d.x, point2d.y)); + } + if (point3d != null) { + ((Atom)clone).setPoint3d(new Point3d(point3d.x, point3d.y, point3d.z)); + } + if (fractionalPoint3d != null) { + ((Atom)clone).setFractionalPoint3d(new Point3d(fractionalPoint3d.x, fractionalPoint3d.y, fractionalPoint3d.z)); + } + connectedAtomsList = new ArrayList(getConnectedAtomsList());//new ArrayList<IAtom>(); + return clone; + } + + public List<IAtom> getConnectedAtomsList() { + return connectedAtomsList ; + } + +} + + + + + Added: detgen/trunk/src/org/openscience/cdk/AtomContainer.java =================================================================== --- detgen/trunk/src/org/openscience/cdk/AtomContainer.java (rev 0) +++ detgen/trunk/src/org/openscience/cdk/AtomContainer.java 2010-03-25 14:29:42 UTC (rev 15495) @@ -0,0 +1,1729 @@ +/* $RCSfile$ + * $Author$ + * $Date$ + * $Revision$ + * + * Copyright (C) 1997-2007 Christoph Steinbeck + * + * Contact: cdk...@li... + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + */ +package org.openscience.cdk; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Hashtable; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.openscience.cdk.interfaces.IAtom; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IAtomParity; +import org.openscience.cdk.interfaces.IBond; +import org.openscience.cdk.interfaces.IChemObjectChangeEvent; +import org.openscience.cdk.interfaces.IChemObjectListener; +import org.openscience.cdk.interfaces.IElectronContainer; +import org.openscience.cdk.interfaces.ILonePair; +import org.openscience.cdk.interfaces.ISingleElectron; +import org.openscience.cdk.interfaces.IBond.Order; + +/** + * Base class for all chemical objects that maintain a list of Atoms and + * ElectronContainers. <p> + * + * Looping over all Bonds in the AtomContainer is typically done like: <pre> + * Iterator iter = atomContainer.bonds(); + * while (iter.hasNext()) { + * IBond aBond = (IBond) iter.next(); + * } + * + * </pre> + * + * @cdk.module data + * @cdk.githash + * + * @author steinbeck + * @cdk.created 2000-10-02 + */ +public class AtomContainer extends ChemObject + implements IAtomContainer, IChemObjectListener, Serializable, Cloneable { + + /** + * Determines if a de-serialized object is compatible with this class. + * + * This value must only be changed if and only if the new version + * of this class is incompatible with the old version. See Sun docs + * for <a href=http://java.sun.com/products/jdk/1.1/docs/guide + * /serialization/spec/version.doc.html>details</a>. + */ + private static final long serialVersionUID = 5678100348445919254L; + + /** + * Number of atoms contained by this object. + */ + protected int atomCount; + + /** + * Number of bonds contained by this object. + */ + protected int bondCount; + + /** + * Number of lone pairs contained by this object. + */ + protected int lonePairCount; + + /** + * Number of single electrons contained by this object. + */ + protected int singleElectronCount; + + /** + * Amount by which the bond and atom arrays grow when elements are added and + * the arrays are not large enough for that. + */ + protected int growArraySize = 10; + + /** + * Internal array of atoms. + */ + protected IAtom[] atoms; + + /** + * Internal array of bonds. + */ + protected IBond[] bonds; + + /** + * Internal array of lone pairs. + */ + protected ILonePair[] lonePairs; + + /** + * Internal array of single electrons. + */ + protected ISingleElectron[] singleElectrons; + + /** + * Internal list of atom parities. + */ + protected Map<IAtom, IAtomParity> atomParities; + + + /** + * Constructs an empty AtomContainer. + */ + public AtomContainer() { + this(10, 10, 0, 0); + } + + + /** + * Constructs an AtomContainer with a copy of the atoms and electronContainers + * of another AtomContainer (A shallow copy, i.e., with the same objects as in + * the original AtomContainer). + * + * @param container An AtomContainer to copy the atoms and electronContainers from + */ + public AtomContainer(IAtomContainer container) + { + this.atomCount = container.getAtomCount(); + this.bondCount = container.getBondCount(); + this.lonePairCount = container.getLonePairCount(); + this.singleElectronCount = container.getSingleElectronCount(); + this.atoms = new IAtom[this.atomCount]; + this.bonds = new IBond[this.bondCount]; + this.lonePairs = new ILonePair[this.lonePairCount]; + this.singleElectrons = new ISingleElectron[this.singleElectronCount]; + + atomParities = new Hashtable<IAtom, IAtomParity>(atomCount/2); + + for (int f = 0; f < container.getAtomCount(); f++) { + atoms[f] = container.getAtom(f); + container.getAtom(f).addListener(this); + } + for (int f = 0; f < this.bondCount; f++) { + bonds[f] = container.getBond(f); + container.getBond(f).addListener(this); + } + for (int f = 0; f < this.lonePairCount; f++) { + lonePairs[f] = container.getLonePair(f); + container.getLonePair(f).addListener(this); + } + for (int f = 0; f < this.singleElectronCount; f++) { + singleElectrons[f] = container.getSingleElectron(f); + container.getSingleElectron(f).addListener(this); + } + } + + + /** + * Constructs an empty AtomContainer that will contain a certain number of + * atoms and electronContainers. It will set the starting array lengths to the + * defined values, but will not create any Atom or ElectronContainer's. + * + *@param atomCount Number of atoms to be in this container + *@param bondCount Number of bonds to be in this container + *@param lpCount Number of lone pairs to be in this container + *@param seCount Number of single electrons to be in this container + * + */ + public AtomContainer(int atomCount, int bondCount, int lpCount, int seCount) + { + this.atomCount = 0; + this.bondCount = 0; + this.lonePairCount = 0; + this.singleElectronCount = 0; + atoms = new IAtom[atomCount]; + bonds = new IBond[bondCount]; + lonePairs = new ILonePair[lpCount]; + singleElectrons = new ISingleElectron[seCount]; + atomParities = new Hashtable<IAtom, IAtomParity>(atomCount/2); + } + + /** + * Adds an AtomParity to this container. If a parity is already given for the + * affected Atom, it is overwritten. + * + * @param parity The new AtomParity for this container + * @see #getAtomParity + */ + public void addAtomParity(IAtomParity parity) { + atomParities.put(parity.getAtom(), parity); + } + + /** + * Returns the atom parity for the given Atom. If no parity is associated + * with the given Atom, it returns null. + * + * @param atom Atom for which the parity must be returned + * @return The AtomParity for the given Atom, or null if that Atom does + * not have an associated AtomParity + * @see #addAtomParity + */ + public IAtomParity getAtomParity(IAtom atom) { + return atomParities.get(atom); + } + + /** + * Sets the array of atoms of this AtomContainer. + * + *@param atoms The array of atoms to be assigned to this AtomContainer + *@see #getAtom + */ + public void setAtoms(IAtom[] atoms) + { + this.atoms = atoms; + for (IAtom atom : atoms) { + atom.addListener(this); + } + this.atomCount = atoms.length; + notifyChanged(); + } + + /** + * Sets the array of bonds of this AtomContainer. + * + * @param bonds The array of bonds to be assigned to + * this AtomContainer + * @see #getBond + */ + public void setBonds(IBond[] bonds) + { + this.bonds = bonds; + for (IBond bond : bonds) { + bond.addListener(this); + } + this.bondCount = bonds.length; + } + + /** + * Sets the array of electronContainers of this AtomContainer. + * + *@param electronContainers The array of electronContainers to be assigned to + * this AtomContainer + *@see #getElectronContainers + */ +// public void setElectronContainers(IElectronContainer[] electronContainers) +// { +// this.electronContainers = electronContainers; +// for (int f = 0; f < electronContainers.length; f++) +// { +// electronContainers[f].addListener(this); +// } +// setElectronContainerCount(electronContainers.length); +// notifyChanged(); +// } + + + /** + * Sets the atom at position <code>number</code> in [0,..]. + * + *@param number The position of the atom to be set. + *@param atom The atom to be stored at position <code>number</code> + *@see #getAtom(int) + */ + public void setAtom(int number, IAtom atom) + { + atom.addListener(this); + atoms[number] = atom; + notifyChanged(); + } + + + /** + * Get the atom at position <code>number</code> in [0,..]. + * + *@param number The position of the atom to be retrieved. + *@return The atomAt value + * @see #setAtom(int, org.openscience.cdk.interfaces.IAtom) + * @see #setAtoms(org.openscience.cdk.interfaces.IAtom[]) + * + */ + public IAtom getAtom(int number) + { + return atoms[number]; + } + + + /** + * Get the bond at position <code>number</code> in [0,..]. + * + *@param number The position of the bond to be retrieved. + *@return The bondAt value + */ + public IBond getBond(int number) + { + return bonds[number]; + } + + /** + * Get the lone pair at position <code>number</code> in [0,..]. + * + *@param number The position of the LonePair to be retrieved. + *@return The lone pair number + */ + public ILonePair getLonePair(int number) + { + return lonePairs[number]; + } + + /** + * Get the single electron at position <code>number</code> in [0,..]. + * + *@param number The position of the SingleElectron to be retrieved. + *@return The single electron number + */ + public ISingleElectron getSingleElectron(int number) + { + return singleElectrons[number]; + } + + /** + * Sets the ElectronContainer at position <code>number</code> in [0,..]. + * + * @param number The position of the ElectronContainer to be set. + * @param electronContainer The ElectronContainer to be stored at position <code>number</code> + * @see #getElectronContainer(int) + */ +// public void setElectronContainer(int number, IElectronContainer electronContainer) +// { +// electronContainer.addListener(this); +// electronContainers[number] = electronContainer; +// notifyChanged(); +// } + + + /** + * Sets the number of electronContainers in this container. + * + * @param electronContainerCount The number of electronContainers in this + * container + * @see #getElectronContainerCount + */ +// public void setElectronContainerCount(int electronContainerCount) +// { +// this.electronContainerCount = electronContainerCount; +// notifyChanged(); +// } + + + /** + * Sets the number of atoms in this container. + * + *@param atomCount The number of atoms in this container + *@see #getAtomCount + */ +// public void setAtomCount(int atomCount) +// { +// this.atomCount = atomCount; +// notifyChanged(); +// } + + + /** + * Returns an Iterable for looping over all atoms in this container. + * + *@return An Iterable with the atoms in this container + */ + public Iterable<IAtom> atoms() + { + return new Iterable<IAtom>() { + public Iterator<IAtom> iterator() { + return new AtomIterator(); + } + }; + } + + /** + * The inner AtomIterator class. + * + */ + private class AtomIterator implements Iterator<IAtom> { + + private int pointer = 0; + + public boolean hasNext() { + return pointer < atomCount; + } + + public IAtom next() { + return atoms[pointer++]; + } + + public void remove() { + removeAtom(--pointer); + } + + } + + /** + * Returns an Iterable for looping over all bonds in this container. + * + *@return An Iterable with the bonds in this container + */ + public Iterable<IBond> bonds() + { + return new Iterable<IBond>() { + public Iterator<IBond> iterator() { + return new BondIterator(); + } + }; + } + + /** + * The inner BondIterator class. + * + */ + private class BondIterator implements Iterator<IBond> { + + private int pointer = 0; + + public boolean hasNext() { + return pointer < bondCount; + } + + public IBond next() { + return bonds[pointer++]; + } + + public void remove() { + removeBond(--pointer); + } + + } + + /** + * Returns an Iterable for looping over all lone pairs in this container. + * + *@return An Iterable with the lone pairs in this container + */ + public Iterable<ILonePair> lonePairs() + { + return new Iterable<ILonePair>() { + public Iterator<ILonePair> iterator() { + return new LonePairIterator(); + } + }; + } + + /** + * The inner LonePairIterator class. + * + */ + private class LonePairIterator implements Iterator<ILonePair> { + + private int pointer = 0; + + public boolean hasNext() { + return pointer < lonePairCount; + } + + public ILonePair next() { + return lonePairs[pointer++]; + } + + public void remove() { + removeLonePair(--pointer); + } + + } + + /** + * Returns an Iterable for looping over all single electrons in this container. + * + *@return An Iterable with the single electrons in this container + */ + public Iterable<ISingleElectron> singleElectrons() + { + return new Iterable<ISingleElectron>() { + public Iterator<ISingleElectron> iterator() { + return new SingleElectronIterator(); + } + }; + } + + /** + * The inner SingleElectronIterator class. + * + */ + private class SingleElectronIterator implements Iterator<ISingleElectron> { + + private int pointer = 0; + + public boolean hasNext() { + return pointer < singleElectronCount; + } + + public ISingleElectron next() { + return singleElectrons[pointer++]; + } + + public void remove() { + removeSingleElectron(--pointer); + } + + } + + /** + * Returns an Iterable for looping over all electron containers in this container. + * + *@return An Iterable with the electron containers in this container + */ + public Iterable<IElectronContainer> electronContainers() + { + return new Iterable<IElectronContainer>() { + public Iterator<IElectronContainer> iterator() { + return new ElectronContainerIterator(); + } + }; + } + + /** + * The inner ElectronContainerIterator class. + * + */ + private class ElectronContainerIterator implements Iterator<IElectronContainer> { + + private int pointer = 0; + + public boolean hasNext() { + return pointer < (bondCount + lonePairCount + singleElectronCount); + } + + public IElectronContainer next() { + if (pointer < bondCount) return bonds[pointer++]; + else if (pointer < bondCount+lonePairCount) return lonePairs[(pointer++)-bondCount]; + else if (pointer < bondCount+lonePairCount+singleElectronCount) return singleElectrons[(pointer++)-bondCount-lonePairCount]; + return null; + } + + public void remove() { + if (pointer <= bondCount) removeBond(--pointer); + else if (pointer <= bondCount+lonePairCount) removeLonePair((--pointer)-bondCount); + else if (pointer <= bondCount+lonePairCount+singleElectronCount) removeSingleElectron((--pointer)-bondCount-lonePairCount); + } + + } + + /** + * Returns the atom at position 0 in the container. + * + *@return The atom at position 0 . + */ + public IAtom getFirstAtom() + { + return atoms[0]; + } + + + /** + * Returns the atom at the last position in the container. + * + *@return The atom at the last position + */ + public IAtom getLastAtom() + { + return getAtomCount() > 0 ? (Atom)atoms[getAtomCount() - 1] : null; + } + + + /** + * Returns the position of a given atom in the atoms array. It returns -1 if + * the atom does not exist. + * + *@param atom The atom to be sought + *@return The Position of the atom in the atoms array in [0,..]. + */ + public int getAtomNumber(IAtom atom) + { + for (int f = 0; f < atomCount; f++) + { + if (atoms[f] == atom) return f; + } + return -1; + } + + + /** + * Returns the position of the bond between two given atoms in the + * electronContainers array. It returns -1 if the bond does not exist. + * + *@param atom1 The first atom + *@param atom2 The second atom + *@return The Position of the bond between a1 and a2 in the + * electronContainers array. + */ + public int getBondNumber(IAtom atom1, IAtom atom2) + { + return (getBondNumber(getBond(atom1, atom2))); + } + + + /** + * Returns the position of a given bond in the electronContainers array. It + * returns -1 if the bond does not exist. + * + *@param bond The bond to be sought + *@return The Position of the bond in the electronContainers array in [0,..]. + */ + public int getBondNumber(IBond bond) + { + for (int f = 0; f < bondCount; f++) + { + if (bonds[f] == bond) return f; + } + return -1; + } + + /** + * Returns the position of a given lone pair in the lone pair array. + * It returns -1 if the lone pair does not exist. + * + *@param lonePair The lone pair to be sought + *@return The Position of the lone pair in the array.. + */ + public int getLonePairNumber(ILonePair lonePair) + { + for (int f = 0; f < lonePairCount; f++) + { + if (lonePairs[f] == lonePair) return f; + } + return -1; + } + + /** + * Returns the position of a given single electron in the single electron array. + * It returns -1 if the single electron does not exist. + * + *@param singleElectron The single electron to be sought + *@return The Position of the single electron in the array. + */ + public int getSingleElectronNumber(ISingleElectron singleElectron) + { + for (int f = 0; f < singleElectronCount; f++) + { + if (singleElectrons[f] == singleElectron) return f; + } + return -1; + } + + /** + * Returns the ElectronContainer at position <code>number</code> in the + * container. + * + * @param number The position of the ElectronContainer to be returned. + * @return The ElectronContainer at position <code>number</code>. + */ + public IElectronContainer getElectronContainer(int number) + { + if (number < this.bondCount) return bonds[number]; + number -= this.bondCount; + if (number < this.lonePairCount) return lonePairs[number]; + number -= this.lonePairCount; + if (number < this.singleElectronCount) return singleElectrons[number]; + return null; + } + + + /** + * Returns the bond that connects the two given atoms. + * + * @param atom1 The first atom + * @param atom2 The second atom + * @return The bond that connects the two atoms + */ + public IBond getBond(IAtom atom1, IAtom atom2) + { + for (int i = 0; i < getBondCount(); i++) + { + if (bonds[i].contains(atom1) && + bonds[i].getConnectedAtom(atom1) == atom2) { + return bonds[i]; + } + } + return null; + } + + /** + * Returns the number of Atoms in this Container. + * + *@return The number of Atoms in this Container + */ + public int getAtomCount() + { + return this.atomCount; + } + + /** + * Returns the number of Bonds in this Container. + * + *@return The number of Bonds in this Container + */ + public int getBondCount() + { + return this.bondCount; + } + + /** + * Returns the number of LonePairs in this Container. + * + *@return The number of LonePairs in this Container + */ + public int getLonePairCount() + { + return this.lonePairCount; + } + + /** + * Returns the number of the single electrons in this container, + * + *@return The number of SingleElectron objects of this AtomContainer + */ + public int getSingleElectronCount() + { + return this.singleElectronCount; + } + + /** + * Returns the number of ElectronContainers in this Container. + * + * @return The number of ElectronContainers in this Container + */ + public int getElectronContainerCount() + { + return this.bondCount + this.lonePairCount + this.singleElectronCount; + } + + /** + * Returns an ArrayList of all atoms connected to the given atom. + * + *@param atom The atom the bond partners are searched of. + *@return The ArrayList with the connected atoms + */ + public List<IAtom> getConnectedAtomsList(IAtom atom) + { + return atom.getConnectedAtomsList(); + } + + /** + * Returns an ArrayList of all Bonds connected to the given atom. + * + *@param atom The atom the connected bonds are searched of + *@return The ArrayList with connected atoms + */ + public List<IBond> getConnectedBondsList(IAtom atom) + { + List<IBond> bondsList = new ArrayList<IBond>(); + for (int i = 0; i < bondCount; i++) + { + if (bonds[i].contains(atom)) bondsList.add(bonds[i]); + } + return bondsList; + } + + /** + * Returns the array of lone pairs connected to an atom. + * + * @param atom The atom for which to get lone pairs + * @return The array of LonePairs of this AtomContainer + * @see #getElectronContainer + * @see #electronContainers() + * @see #getBond + */ + public List<ILonePair> getConnectedLonePairsList(IAtom atom) { + List<ILonePair> lps = new ArrayList<ILonePair>(); + for (int i = 0; i < lonePairCount; i++) { + if (lonePairs[i].contains(atom)) lps.add(lonePairs[i]); + } + return lps; + } + + /** + * Returns an array of all SingleElectron connected to the given atom. + * + *@param atom The atom on which the single electron is located + *@return The array of SingleElectron of this AtomContainer + */ + public List<ISingleElectron> getConnectedSingleElectronsList(IAtom atom) + { + List<ISingleElectron> lps = new ArrayList<ISingleElectron>(); + for (int i = 0; i < singleElectronCount; i++) + { + if (singleElectrons[i].contains(atom)) lps.add(singleElectrons[i]); + } + return lps; + } + + /** + * Returns an ArrayList of all electronContainers connected to the given atom. + * + *@param atom The atom the connected electronContainers are searched of + *@return The ArrayList with the connected atoms + */ + public List<IElectronContainer> getConnectedElectronContainersList(IAtom atom) + { + List<IElectronContainer> lps = new ArrayList<IElectronContainer>(); + for (int i = 0; i < bondCount; i++) + { + if (bonds[i].contains(atom)) lps.add(bonds[i]); + } + for (int i = 0; i < lonePairCount; i++) + { + if (lonePairs[i].contains(atom)) lps.add(lonePairs[i]); + } + for (int i = 0; i < singleElectronCount; i++) + { + if (singleElectrons[i].contains(atom)) lps.add(singleElectrons[i]); + } + return lps; + } + + /** + * Returns the number of atoms connected to the given atom. + * + *@param atom The atom the number of bond partners are searched of. + *@return The the size of connected atoms + */ + public int getConnectedAtomsCount(IAtom atom) + { + int count = 0; + for (int i = 0; i < bondCount; i++) + { + if (bonds[i].contains(atom)) ++count; + } + return count; + } + + /** + * Returns the number of Bonds for a given Atom. + * + *@param atom The atom + *@return The number of Bonds for this atom + */ + public int getConnectedBondsCount(IAtom atom) + { + return getConnectedAtomsCount(atom); + } + + /** + * Returns the number of connected atoms (degree) to the given atom. + * + *@param atomNumber The atomnumber the degree is searched for + *@return The number of connected atoms (degree) + */ + public int getConnectedBondsCount(int atomNumber) + { + return getConnectedAtomsCount(atoms[atomNumber]); + } + + /** + * Returns the number of LonePairs for a given Atom. + * + *@param atom The atom + *@return The number of LonePairs for this atom + */ + public int getConnectedLonePairsCount(IAtom atom) + { + int count = 0; + for (int i = 0; i < lonePairCount; i++) + { + if (lonePairs[i].contains(atom)) ++count; + } + return count; + } + + /** + * Returns the sum of the SingleElectron for a given Atom. + * + *@param atom The atom on which the single electron is located + *@return The array of SingleElectron of this AtomContainer + */ + public int getConnectedSingleElectronsCount(IAtom atom) + { + int count = 0; + for (int i = 0; i < singleElectronCount; i++) + { + if (singleElectrons[i].contains(atom)) ++count; + } + return count; + } + + + /** + * Returns the sum of the bond orders for a given Atom. + * + * @param atom The atom + * @return The number of bond orders for this atom + * + * @deprecated Replaced by <code>AtomContainerManipulator#getBondOrderSum(IAtomContainer, IAtom)</code> + */ + public double getBondOrderSum(IAtom atom) + { + double count = 0; + for (int i = 0; i < bondCount; i++) + { + if (bonds[i].contains(atom)) { + if (bonds[i].getOrder() == IBond.Order.SINGLE) { + count += 1; + } else if (bonds[i].getOrder() == IBond.... [truncated message content] |