Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
2,016 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
120 changes: 120 additions & 0 deletions
120
src/main/org/openscience/cdk/signature/AtomSignature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
/* Copyright (C) 2009-2010 maclean {gilleain.torrance@gmail.com} | ||
* | ||
* Contact: cdk-devel@lists.sourceforge.net | ||
* | ||
* 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.signature; | ||
|
||
import java.util.List; | ||
|
||
import org.openscience.cdk.annotations.TestClass; | ||
import org.openscience.cdk.interfaces.IAtom; | ||
import org.openscience.cdk.interfaces.IAtomContainer; | ||
import org.openscience.cdk.interfaces.IBond; | ||
|
||
import signature.AbstractVertexSignature; | ||
|
||
/** | ||
* The signature for a molecule rooted at a particular atom. | ||
* | ||
* @cdk.module signature | ||
* @author maclean | ||
* | ||
*/ | ||
@TestClass("org.openscience.cdk.signature.AtomSignatureTest") | ||
public class AtomSignature extends AbstractVertexSignature { | ||
|
||
/** | ||
* The atom container to make signatures from | ||
*/ | ||
private IAtomContainer molecule; | ||
|
||
/** | ||
* Create an atom signature starting at <code>atomIndex</code>. | ||
* | ||
* @param atomIndex the index of the atom that roots this signature | ||
* @param molecule the molecule to create the signature from | ||
*/ | ||
public AtomSignature(int atomIndex, IAtomContainer molecule) { | ||
super(); | ||
this.molecule = molecule; | ||
super.createMaximumHeight(atomIndex, molecule.getAtomCount()); | ||
} | ||
|
||
/** | ||
* Create an atom signature starting at <code>atomIndex</code> and with a | ||
* maximum height of <code>h</code>. | ||
* | ||
* @param atomIndex the index of the atom that roots this signature | ||
* @param height the maximum height of the signature | ||
* @param molecule the molecule to create the signature from | ||
*/ | ||
public AtomSignature(int atomIndex, int height, IAtomContainer molecule) { | ||
super(); | ||
this.molecule = molecule; | ||
super.create(atomIndex, molecule.getAtomCount(), height); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see signature.AbstractVertexSignature#getConnected(int) | ||
*/ | ||
@Override | ||
public int[] getConnected(int vertexIndex) { | ||
IAtom atom = this.molecule.getAtom(vertexIndex); | ||
List<IAtom> connected = this.molecule.getConnectedAtomsList(atom); | ||
int[] connectedIndices = new int[connected.size()]; | ||
int i = 0; | ||
for (IAtom otherAtom : connected) { | ||
connectedIndices[i++] = this.molecule.getAtomNumber(otherAtom); | ||
} | ||
return connectedIndices; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see signature.AbstractVertexSignature#getEdgeLabel(int, int) | ||
*/ | ||
@Override | ||
public String getEdgeLabel(int vertexIndex, int otherVertexIndex) { | ||
IAtom atomA = this.molecule.getAtom(vertexIndex); | ||
IAtom atomB = this.molecule.getAtom(otherVertexIndex); | ||
IBond bond = this.molecule.getBond(atomA, atomB); | ||
if (bond != null) { | ||
switch (bond.getOrder()) { | ||
// case SINGLE: return "-"; | ||
case SINGLE: return ""; | ||
case DOUBLE: return "="; | ||
case TRIPLE: return "#"; | ||
case QUADRUPLE: return "$"; | ||
default: return ""; | ||
} | ||
} else { | ||
return ""; | ||
} | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see signature.AbstractVertexSignature#getVertexSymbol(int) | ||
*/ | ||
@Override | ||
public String getVertexSymbol(int vertexIndex) { | ||
return this.molecule.getAtom(vertexIndex).getSymbol(); | ||
} | ||
|
||
} |
110 changes: 110 additions & 0 deletions
110
src/main/org/openscience/cdk/signature/MoleculeFromSignatureBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
/* Copyright (C) 2009-2010 maclean {gilleain.torrance@gmail.com} | ||
* | ||
* Contact: cdk-devel@lists.sourceforge.net | ||
* | ||
* 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.signature; | ||
|
||
import org.openscience.cdk.annotations.TestClass; | ||
import org.openscience.cdk.interfaces.IAtom; | ||
import org.openscience.cdk.interfaces.IAtomContainer; | ||
import org.openscience.cdk.interfaces.IBond; | ||
import org.openscience.cdk.interfaces.IChemObjectBuilder; | ||
import org.openscience.cdk.nonotify.NoNotificationChemObjectBuilder; | ||
|
||
import signature.AbstractGraphBuilder; | ||
|
||
/** | ||
* Builds a molecule from a signature. | ||
* | ||
* @cdk.module signature | ||
* @author maclean | ||
* | ||
*/ | ||
@TestClass("org.openscience.cdk.signature.MoleculeFromSignatureBuilderTest") | ||
public class MoleculeFromSignatureBuilder extends AbstractGraphBuilder { | ||
|
||
/** | ||
* The chem object builder | ||
*/ | ||
private IChemObjectBuilder builder; | ||
|
||
/** | ||
* The container that is being constructed | ||
*/ | ||
private IAtomContainer container; | ||
|
||
/** | ||
* This default constructor uses a {@link NoNotificationChemObjectBuilder} | ||
*/ | ||
public MoleculeFromSignatureBuilder() { | ||
this.builder = NoNotificationChemObjectBuilder.getInstance(); | ||
} | ||
|
||
/** | ||
* Uses the chem object builder for making molecules. | ||
* | ||
* @param builder a builder for CDK molecules. | ||
*/ | ||
public MoleculeFromSignatureBuilder(IChemObjectBuilder builder) { | ||
this.builder = builder; | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see signature.AbstractGraphBuilder#makeEdge(int, int, java.lang.String, java.lang.String, java.lang.String) | ||
*/ | ||
@Override | ||
public void makeEdge(int vertexIndex1, int vertexIndex2, | ||
String vertexSymbol1, String vertexSymbol2, String edgeLabel) { | ||
if (edgeLabel.equals("")) { | ||
container.addBond(vertexIndex1, vertexIndex2, IBond.Order.SINGLE); | ||
} else if (edgeLabel.equals("=")) { | ||
container.addBond(vertexIndex1, vertexIndex2, IBond.Order.DOUBLE); | ||
} else if (edgeLabel.equals("#")) { | ||
container.addBond(vertexIndex1, vertexIndex2, IBond.Order.TRIPLE); | ||
} | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see signature.AbstractGraphBuilder#makeGraph() | ||
*/ | ||
@Override | ||
public void makeGraph() { | ||
this.container = this.builder.newInstance(IAtomContainer.class); | ||
} | ||
|
||
/* (non-Javadoc) | ||
* @see signature.AbstractGraphBuilder#makeVertex(java.lang.String) | ||
*/ | ||
@Override | ||
public void makeVertex(String label) { | ||
this.container.addAtom(this.builder.newInstance(IAtom.class, label)); | ||
} | ||
|
||
/** | ||
* Gets the atom container. | ||
* | ||
* @return the constructed atom container | ||
*/ | ||
public IAtomContainer getAtomContainer() { | ||
return this.container; | ||
} | ||
|
||
} |
145 changes: 145 additions & 0 deletions
145
src/main/org/openscience/cdk/signature/MoleculeSignature.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
/* Copyright (C) 2009-2010 maclean {gilleain.torrance@gmail.com} | ||
* | ||
* Contact: cdk-devel@lists.sourceforge.net | ||
* | ||
* 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.signature; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.openscience.cdk.annotations.TestClass; | ||
import org.openscience.cdk.interfaces.IAtomContainer; | ||
import org.openscience.cdk.interfaces.IMolecule; | ||
|
||
import signature.AbstractGraphSignature; | ||
import signature.AbstractVertexSignature; | ||
import signature.ColoredTree; | ||
import signature.SymmetryClass; | ||
|
||
/** | ||
* A signature for an entire molecule. | ||
* | ||
* @cdk.module signature | ||
* @author maclean | ||
* | ||
*/ | ||
@TestClass("org.openscience.cdk.signature.MoleculeSignatureTest") | ||
public class MoleculeSignature extends AbstractGraphSignature { | ||
|
||
private IAtomContainer molecule; | ||
|
||
/** | ||
* Creates a signature that represents this molecule. | ||
* | ||
* @param molecule the molecule to convert to a signature | ||
*/ | ||
public MoleculeSignature(IAtomContainer molecule) { | ||
super(); | ||
this.molecule = molecule; | ||
} | ||
|
||
/** | ||
* Creates a signature with a maximum height of <code>height</code> | ||
* for molecule <code>molecule</code>. | ||
* | ||
* @param molecule the molecule to convert to a signature | ||
* @param height the maximum height of the signature | ||
*/ | ||
public MoleculeSignature(IMolecule molecule, int height) { | ||
super(height); | ||
this.molecule = molecule; | ||
} | ||
|
||
@Override | ||
public int getVertexCount() { | ||
return this.molecule.getAtomCount(); | ||
} | ||
|
||
@Override | ||
public String signatureStringForVertex(int vertexIndex) { | ||
AtomSignature atomSignature; | ||
int height = super.getHeight(); | ||
if (height == -1) { | ||
atomSignature = new AtomSignature(vertexIndex, this.molecule); | ||
} else { | ||
atomSignature = | ||
new AtomSignature(vertexIndex, height, this.molecule); | ||
} | ||
return atomSignature.toCanonicalString(); | ||
} | ||
|
||
@Override | ||
public String signatureStringForVertex(int vertexIndex, int height) { | ||
AtomSignature atomSignature = | ||
new AtomSignature(vertexIndex, height, this.molecule); | ||
return atomSignature.toCanonicalString(); | ||
} | ||
|
||
@Override | ||
public AbstractVertexSignature signatureForVertex(int vertexIndex) { | ||
return new AtomSignature(vertexIndex, this.molecule); | ||
} | ||
|
||
/** | ||
* Calculates the orbits of the atoms of the molecule. | ||
* | ||
* @return a list of orbits | ||
*/ | ||
public List<Orbit> calculateOrbits() { | ||
List<Orbit> orbits = new ArrayList<Orbit>(); | ||
List<SymmetryClass> symmetryClasses = super.getSymmetryClasses(); | ||
for (SymmetryClass symmetryClass : symmetryClasses) { | ||
Orbit orbit = new Orbit(symmetryClass.getSignatureString(), -1); | ||
for (int atomIndex : symmetryClass) { | ||
orbit.addAtom(atomIndex); | ||
} | ||
orbits.add(orbit); | ||
} | ||
return orbits; | ||
} | ||
|
||
/** | ||
* Builder for molecules (rather, for atom containers) from signature | ||
* strings. | ||
* | ||
* @param signatureString the signature string to use | ||
* @return an atom container | ||
*/ | ||
public static IAtomContainer fromSignatureString(String signatureString) { | ||
ColoredTree tree = AtomSignature.parse(signatureString); | ||
MoleculeFromSignatureBuilder builder = | ||
new MoleculeFromSignatureBuilder(); | ||
builder.makeFromColoredTree(tree); | ||
return builder.getAtomContainer(); | ||
} | ||
|
||
public String toCanonicalSignatureString(int height) { | ||
String canonicalSignature = null; | ||
for (int i = 0; i < getVertexCount(); i++) { | ||
String signatureForI = signatureStringForVertex(i, height); | ||
if (canonicalSignature == null || | ||
canonicalSignature.compareTo(signatureForI) < 0) { | ||
canonicalSignature = signatureForI; | ||
} | ||
} | ||
return canonicalSignature; | ||
} | ||
} |
Oops, something went wrong.