Navigation Menu

Skip to content

Commit

Permalink
More Molecule use removed
Browse files Browse the repository at this point in the history
Signed-off-by: Rajarshi  Guha <rajarshi.guha@gmail.com>
  • Loading branch information
egonw authored and rajarshi committed Dec 11, 2011
1 parent 1d8ee25 commit 0a04d3f
Show file tree
Hide file tree
Showing 56 changed files with 411 additions and 437 deletions.
6 changes: 3 additions & 3 deletions src/main/org/openscience/cdk/io/inchi/INChIHandler.java
Expand Up @@ -18,11 +18,11 @@
*/
package org.openscience.cdk.io.inchi;

import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.AtomContainerSet;
import org.openscience.cdk.ChemFile;
import org.openscience.cdk.ChemModel;
import org.openscience.cdk.ChemSequence;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomContainerSet;
import org.openscience.cdk.tools.ILoggingTool;
Expand Down Expand Up @@ -100,7 +100,7 @@ public void endElement(String uri, String local, String raw) {
} else if ("formula".equals(local)) {
if (tautomer != null) {
logger.info("Parsing <formula> chars: ", currentChars);
tautomer = new Molecule(inchiTool.processFormula(
tautomer = new AtomContainer(inchiTool.processFormula(
setOfMolecules.getBuilder().newInstance(IAtomContainer.class), currentChars
));
} else {
Expand Down Expand Up @@ -141,7 +141,7 @@ public void startElement(String uri, String local,
logger.info("INChI version: ", atts.getValue(i));
}
} else if ("structure".equals(local)) {
tautomer = new Molecule();
tautomer = new AtomContainer();
} else {
// skip all other elements
}
Expand Down
19 changes: 10 additions & 9 deletions src/main/org/openscience/cdk/iupac/parser/MoleculeBuilder.java
Expand Up @@ -28,13 +28,14 @@
import java.util.Vector;

import org.openscience.cdk.Atom;
import org.openscience.cdk.AtomContainer;
import org.openscience.cdk.Bond;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.Ring;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
import org.openscience.cdk.atomtype.CDKAtomTypeMatcher;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.interfaces.IAtomType;
import org.openscience.cdk.interfaces.IBond;
import org.openscience.cdk.interfaces.IBond.Order;
Expand All @@ -58,7 +59,7 @@
public class MoleculeBuilder
{
/** The molecule which is worked upon throughout the class and returned at the end */
private Molecule currentMolecule = new Molecule();
private IAtomContainer currentMolecule = new AtomContainer();
private IAtom endOfChain;

/**
Expand All @@ -68,16 +69,16 @@ public class MoleculeBuilder
* @param isMainCyclic A flag to show if the molecule is a ring. 0 means not a ring, 1 means is a ring.
* @return A Molecule containing the requested chain.
*/
private Molecule buildChain(int length, boolean isMainCyclic)
private IAtomContainer buildChain(int length, boolean isMainCyclic)
{
Molecule currentChain;
IAtomContainer currentChain;
if (length > 0)
{
//If is cyclic
if (isMainCyclic)
{
//Rely on CDK's ring class constructor to generate our cyclic molecules.
currentChain = new Molecule();
currentChain = new AtomContainer();
currentChain.add(new Ring(length, "C"));
} //Else must not be cyclic
else
Expand All @@ -87,7 +88,7 @@ private Molecule buildChain(int length, boolean isMainCyclic)
}
else
{
currentChain = new Molecule();
currentChain = new AtomContainer();
}

return currentChain;
Expand Down Expand Up @@ -293,7 +294,7 @@ else if (funGroupToken == "nitrile" )
//Benzene
else if (funGroupToken == "phenyl" )
{
Molecule benzene = MoleculeFactory.makeBenzene();
IAtomContainer benzene = MoleculeFactory.makeBenzene();
//Detect Aromacity in the benzene ring.
try
{
Expand Down Expand Up @@ -508,7 +509,7 @@ private void addHeads(Vector attachedSubstituents)
connectingAtom = currentMolecule.getAtom(joinLocation);
}

Molecule subChain = buildChain(attachedSubstituent.getLength(), false);
IAtomContainer subChain = buildChain(attachedSubstituent.getLength(), false);

Bond linkingBond = new Bond(subChain.getFirstAtom(), connectingAtom);
currentMolecule.addBond(linkingBond);
Expand All @@ -527,7 +528,7 @@ private void addHeads(Vector attachedSubstituents)
* @param isMainCyclic An indiacation of if the main chain is cyclic.
* @return The molecule as built from the parsed tokens.
*/
protected Molecule buildMolecule(int mainChain, Vector attachedSubstituents
protected IAtomContainer buildMolecule(int mainChain, Vector attachedSubstituents
, Vector attachedGroups, boolean isMainCyclic, String name) throws
ParseException, CDKException
{
Expand Down
6 changes: 3 additions & 3 deletions src/main/org/openscience/cdk/iupac/parser/NomParser.jj
Expand Up @@ -26,7 +26,7 @@ PARSER_BEGIN(NomParser)
package org.openscience.cdk.iupac.parser;

import java.io.StringReader;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.exception.*;
import java.util.*;

Expand Down Expand Up @@ -71,7 +71,7 @@ public class NomParser {
* @throws ParseException Any error which occur in the parsing get wrapped
* up in a ParseException and thrown.
*/
public static Molecule generate (String stringToParse) throws ParseException, CDKException
public static IAtomContainer generate (String stringToParse) throws ParseException, CDKException
{
isMainCyclic = false;
tempLocation = new Vector();
Expand All @@ -90,7 +90,7 @@ public class NomParser {
checkConnections (attachedGroups.iterator());

MoleculeBuilder moleculeBuilder = new MoleculeBuilder();
Molecule returnedMolecule = moleculeBuilder.buildMolecule(mainChainPrefix, attachedSubstituents, attachedGroups, isMainCyclic, stringToParse);
IAtomContainer returnedMolecule = moleculeBuilder.buildMolecule(mainChainPrefix, attachedSubstituents, attachedGroups, isMainCyclic, stringToParse);

return returnedMolecule;
}
Expand Down
Expand Up @@ -20,7 +20,15 @@
*/
package org.openscience.cdk.qsar.descriptors.atomic;

import org.openscience.cdk.Molecule;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
Expand All @@ -35,15 +43,6 @@
import org.openscience.cdk.tools.LonePairElectronChecker;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;

/**
* This class returns the ionization potential of an atom containg lone
* pair electrons. It is
Expand Down Expand Up @@ -256,7 +255,7 @@ public double extractIP(IAtomContainer container, IAtom atom) {
int exactSphere = 0;
String hoseCode = "";
for(int spheres = maxSpheresToUse; spheres > 0; spheres--){
hcg.getSpheres((Molecule) container, atom, spheres, true);
hcg.getSpheres(container, atom, spheres, true);
List<IAtom> atoms = hcg.getNodesInSphere(spheres);
if(atoms.size() != 0){
exactSphere = spheres;
Expand Down
Expand Up @@ -24,7 +24,6 @@
*/
package org.openscience.cdk.qsar.descriptors.atomic;

import org.openscience.cdk.Molecule;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.aromaticity.CDKHueckelAromaticityDetector;
Expand Down Expand Up @@ -153,7 +152,7 @@ public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer) {
IAtom clonedAtom = clonedAtomContainer.getAtom(atomContainer.getAtomNumber(atom));

boolean isProtonInPiSystem = false;
Molecule mol = new Molecule(clonedAtomContainer);
IAtomContainer mol = clonedAtom.getBuilder().newInstance(IAtomContainer.class, clonedAtomContainer);
if (checkAromaticity) {
try {
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
Expand Down
Expand Up @@ -20,7 +20,15 @@
*/
package org.openscience.cdk.qsar.descriptors.atomic;

import org.openscience.cdk.Molecule;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;

import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
import org.openscience.cdk.exception.CDKException;
Expand All @@ -34,15 +42,6 @@
import org.openscience.cdk.tools.LonePairElectronChecker;
import org.openscience.cdk.tools.manipulator.AtomContainerManipulator;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.StringTokenizer;

/**
* This class returns the proton affinity of an atom containing.
*
Expand Down Expand Up @@ -238,7 +237,7 @@ public double extractAffinity(IAtomContainer container, IAtom atom) {
int exactSphere = 0;
String hoseCode = "";
for(int spheres = maxSpheresToUse; spheres > 0; spheres--){
hcg.getSpheres((Molecule) container, atom, spheres, true);
hcg.getSpheres(container, atom, spheres, true);
List<IAtom> atoms = hcg.getNodesInSphere(spheres);
if(atoms.size() != 0){
exactSphere = spheres;
Expand Down
Expand Up @@ -29,7 +29,6 @@
import javax.vecmath.Vector3d;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.Ring;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
Expand Down Expand Up @@ -199,7 +198,7 @@ public DescriptorValue calculate(IAtom atom,
// ///////////////////////AND AROMATICITY AND PI-SYSTEM AND RINGS
// DETECTION

Molecule mol = new Molecule(varAtomContainer);
IAtomContainer mol = varAtomContainer.getBuilder().newInstance(IAtomContainer.class, varAtomContainer);
if (varAtomContainer != acold) {
acold = varAtomContainer;
// DETECTION OF pi SYSTEMS
Expand Down Expand Up @@ -576,7 +575,7 @@ && getIfBondIsNotRotatable(

// Others definitions

private boolean getIfBondIsNotRotatable(Molecule mol,
private boolean getIfBondIsNotRotatable(IAtomContainer mol,
IBond bond, IAtomContainer detected) {
boolean isBondNotRotatable = false;
int counter = 0;
Expand Down Expand Up @@ -609,7 +608,7 @@ private boolean getIfBondIsNotRotatable(Molecule mol,
return isBondNotRotatable;
}

private boolean getIfACarbonIsDoubleBondedToAnOxygen(Molecule mol,
private boolean getIfACarbonIsDoubleBondedToAnOxygen(IAtomContainer mol,
IAtom carbonAtom) {
boolean isDoubleBondedToOxygen = false;
List<IAtom> neighToCarbon = mol.getConnectedAtomsList(carbonAtom);
Expand Down Expand Up @@ -679,7 +678,7 @@ private double calculateDistanceBetweenTwoAtoms(IAtom atom1, IAtom atom2) {

// given a double bond
// this method returns a bond bonded to this double bond
private int getNearestBondtoAGivenAtom(Molecule mol, IAtom atom,
private int getNearestBondtoAGivenAtom(IAtomContainer mol, IAtom atom,
IBond bond) {
int nearestBond = 0;
double[] values;
Expand Down
Expand Up @@ -29,7 +29,6 @@
import javax.vecmath.Vector3d;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.Ring;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
Expand Down Expand Up @@ -191,7 +190,7 @@ public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer, IRing
/////////////////////////FIRST SECTION OF MAIN METHOD: DEFINITION OF MAIN VARIABLES
/////////////////////////AND AROMATICITY AND PI-SYSTEM AND RINGS DETECTION

Molecule mol = new Molecule(varAtomContainer);
IAtomContainer mol = varAtomContainer.getBuilder().newInstance(IAtomContainer.class, varAtomContainer);
if (varAtomContainer != acold) {
acold = varAtomContainer;
// DETECTION OF pi SYSTEMS
Expand Down Expand Up @@ -453,7 +452,7 @@ public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer, IRing

//Others definitions

private boolean getIfBondIsNotRotatable(Molecule mol, IBond bond, IAtomContainer detected) {
private boolean getIfBondIsNotRotatable(IAtomContainer mol, IBond bond, IAtomContainer detected) {
boolean isBondNotRotatable = false;
int counter = 0;
IAtom atom0 = bond.getAtom(0);
Expand All @@ -479,7 +478,7 @@ private boolean getIfBondIsNotRotatable(Molecule mol, IBond bond, IAtomContainer
return isBondNotRotatable;
}

private boolean getIfACarbonIsDoubleBondedToAnOxygen(Molecule mol, IAtom carbonAtom) {
private boolean getIfACarbonIsDoubleBondedToAnOxygen(IAtomContainer mol, IAtom carbonAtom) {
boolean isDoubleBondedToOxygen = false;
List<IAtom> neighToCarbon = mol.getConnectedAtomsList(carbonAtom);
IBond tmpBond;
Expand Down Expand Up @@ -539,7 +538,7 @@ private double calculateDistanceBetweenTwoAtoms(IAtom atom1, IAtom atom2) {

// given a double bond
// this method returns a bond bonded to this double bond
private int getNearestBondtoAGivenAtom(Molecule mol, IAtom atom, IBond bond) {
private int getNearestBondtoAGivenAtom(IAtomContainer mol, IAtom atom, IBond bond) {
int nearestBond = 0;
double[] values;
double distance = 0;
Expand Down
Expand Up @@ -29,7 +29,6 @@
import javax.vecmath.Vector3d;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.Molecule;
import org.openscience.cdk.Ring;
import org.openscience.cdk.annotations.TestClass;
import org.openscience.cdk.annotations.TestMethod;
Expand Down Expand Up @@ -189,7 +188,7 @@ public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer, IRing
/////////////////////////FIRST SECTION OF MAIN METHOD: DEFINITION OF MAIN VARIABLES
/////////////////////////AND AROMATICITY AND PI-SYSTEM AND RINGS DETECTION

Molecule mol = new Molecule(varAtomContainer);
IAtomContainer mol = varAtomContainer.getBuilder().newInstance(IAtomContainer.class, varAtomContainer);
if (varAtomContainer != acold) {
acold = varAtomContainer;
// DETECTION OF pi SYSTEMS
Expand Down Expand Up @@ -420,7 +419,7 @@ public DescriptorValue calculate(IAtom atom, IAtomContainer atomContainer, IRing

//Others definitions

private boolean getIfBondIsNotRotatable(Molecule mol, IBond bond, IAtomContainer detected) {
private boolean getIfBondIsNotRotatable(IAtomContainer mol, IBond bond, IAtomContainer detected) {
boolean isBondNotRotatable = false;
int counter = 0;
IAtom atom0 = bond.getAtom(0);
Expand All @@ -446,7 +445,7 @@ private boolean getIfBondIsNotRotatable(Molecule mol, IBond bond, IAtomContainer
return isBondNotRotatable;
}

private boolean getIfACarbonIsDoubleBondedToAnOxygen(Molecule mol, IAtom carbonAtom) {
private boolean getIfACarbonIsDoubleBondedToAnOxygen(IAtomContainer mol, IAtom carbonAtom) {
boolean isDoubleBondedToOxygen = false;
List<IAtom> neighToCarbon = mol.getConnectedAtomsList(carbonAtom);
IBond tmpBond;
Expand Down Expand Up @@ -507,7 +506,7 @@ private double calculateDistanceBetweenTwoAtoms(IAtom atom1, IAtom atom2) {

// given a double bond
// this method returns a bond bonded to this double bond
private int getNearestBondtoAGivenAtom(Molecule mol, IAtom atom, IBond bond) {
private int getNearestBondtoAGivenAtom(IAtomContainer mol, IAtom atom, IBond bond) {
int nearestBond = 0;
double[] values;
double distance = 0;
Expand Down

0 comments on commit 0a04d3f

Please sign in to comment.