Skip to content

Commit

Permalink
Added some utility methods prior to refactoring. Changed bitwise ANDs…
Browse files Browse the repository at this point in the history
… to boolean ANDs.

Signed-off-by: John May <john.wilkinsonmay@gmail.com>
  • Loading branch information
Mark B Vine authored and johnmay committed Sep 2, 2014
1 parent 315e6bf commit 31e196e
Show file tree
Hide file tree
Showing 2 changed files with 196 additions and 17 deletions.
@@ -1,4 +1,5 @@
/* Copyright (C) 2005-2007 Christian Hoppe <chhoppe@users.sf.net>
* 2014 Mark B Vine (orcid:0000-0002-7794-0426)
*
* Contact: cdk-devel@list.sourceforge.net
*
Expand Down Expand Up @@ -229,15 +230,15 @@ public void zmatrixChainToCartesian(IAtomContainer molecule, boolean flag_branch
n1.normalize();

Vector3d n2 = null;
if (index == 3 & flag_branched) {
if (index == 3 && flag_branched) {
n2 = AtomTetrahedralLigandPlacer3D.rotate(n1, bc, DIHEDRAL_BRANCHED_CHAIN);
} else {
n2 = AtomTetrahedralLigandPlacer3D.rotate(n1, bc, dihedrals[index]);
}
n2.normalize();

Vector3d ba = new Vector3d();
if (index == 3 & flag_branched) {
if (index == 3 && flag_branched) {
ba = AtomTetrahedralLigandPlacer3D.rotate(cd, n2, (-angles[index] / 180) * Math.PI);
ba = AtomTetrahedralLigandPlacer3D.rotate(ba, cd, (-angles[index] / 180) * Math.PI);
} else {
Expand Down Expand Up @@ -384,13 +385,13 @@ public IAtom getNextUnplacedHeavyAtomWithAliphaticPlacedNeighbour(IAtomContainer
Iterator<IBond> bonds = molecule.bonds().iterator();
while (bonds.hasNext()) {
IBond bond = bonds.next();
if (bond.getAtom(0).getFlag(CDKConstants.ISPLACED) & !(bond.getAtom(1).getFlag(CDKConstants.ISPLACED))) {
if (bond.getAtom(1).getFlag(CDKConstants.ISALIPHATIC) & !bond.getAtom(1).getSymbol().equals("H")) {
if (bond.getAtom(0).getFlag(CDKConstants.ISPLACED) && !(bond.getAtom(1).getFlag(CDKConstants.ISPLACED))) {
if (bond.getAtom(1).getFlag(CDKConstants.ISALIPHATIC) && !bond.getAtom(1).getSymbol().equals("H")) {
return bond.getAtom(1);
}
}
if (bond.getAtom(1).getFlag(CDKConstants.ISPLACED) & !(bond.getAtom(0).getFlag(CDKConstants.ISPLACED))) {
if (bond.getAtom(0).getFlag(CDKConstants.ISALIPHATIC) & !bond.getAtom(0).getSymbol().equals("H")) {
if (bond.getAtom(1).getFlag(CDKConstants.ISPLACED) && !(bond.getAtom(0).getFlag(CDKConstants.ISPLACED))) {
if (bond.getAtom(0).getFlag(CDKConstants.ISALIPHATIC) && !bond.getAtom(0).getSymbol().equals("H")) {
return bond.getAtom(0);
}
}
Expand All @@ -410,13 +411,13 @@ public IAtom getNextPlacedHeavyAtomWithUnplacedAliphaticNeighbour(IAtomContainer
IBond bond = bonds.next();
IAtom atom0 = bond.getAtom(0);
IAtom atom1 = bond.getAtom(1);
if (atom0.getFlag(CDKConstants.ISPLACED) & !(atom1.getFlag(CDKConstants.ISPLACED))) {
if (atom1.getFlag(CDKConstants.ISALIPHATIC) & !atom0.getSymbol().equals("H") & !atom1.getSymbol().equals("H")) {
if (atom0.getFlag(CDKConstants.ISPLACED) && !(atom1.getFlag(CDKConstants.ISPLACED))) {
if (atom1.getFlag(CDKConstants.ISALIPHATIC) && !atom0.getSymbol().equals("H") && !atom1.getSymbol().equals("H")) {
return atom0;
}
}
if (atom1.getFlag(CDKConstants.ISPLACED) & !(atom0.getFlag(CDKConstants.ISPLACED))) {
if (atom0.getFlag(CDKConstants.ISALIPHATIC) & !atom1.getSymbol().equals("H") & !atom0.getSymbol().equals("H")) {
if (atom1.getFlag(CDKConstants.ISPLACED) && !(atom0.getFlag(CDKConstants.ISPLACED))) {
if (atom0.getFlag(CDKConstants.ISALIPHATIC) && !atom1.getSymbol().equals("H") && !atom0.getSymbol().equals("H")) {
return atom1;
}
}
Expand All @@ -436,13 +437,13 @@ public IAtom getNextPlacedHeavyAtomWithUnplacedRingNeighbour(IAtomContainer mole
IBond bond = bonds.next();
IAtom atom0 = bond.getAtom(0);
IAtom atom1 = bond.getAtom(1);
if (atom0.getFlag(CDKConstants.ISPLACED) & !(atom1.getFlag(CDKConstants.ISPLACED))) {
if (atom1.getFlag(CDKConstants.ISINRING) & !atom0.getSymbol().equals("H") & !atom1.getSymbol().equals("H")) {
if (atom0.getFlag(CDKConstants.ISPLACED) && !(atom1.getFlag(CDKConstants.ISPLACED))) {
if (atom1.getFlag(CDKConstants.ISINRING) && !atom0.getSymbol().equals("H") && !atom1.getSymbol().equals("H")) {
return atom0;
}
}
if (atom1.getFlag(CDKConstants.ISPLACED) & !(atom0.getFlag(CDKConstants.ISPLACED))) {
if (atom0.getFlag(CDKConstants.ISINRING) & !atom1.getSymbol().equals("H") & !atom0.getSymbol().equals("H")) {
if (atom1.getFlag(CDKConstants.ISPLACED) && !(atom0.getFlag(CDKConstants.ISPLACED))) {
if (atom0.getFlag(CDKConstants.ISINRING) && !atom1.getSymbol().equals("H") && !atom0.getSymbol().equals("H")) {
return atom1;
}
}
Expand Down Expand Up @@ -511,7 +512,7 @@ public IAtom getPlacedHeavyAtom(IAtomContainer molecule, IAtom atom) {
List<IBond> bonds = molecule.getConnectedBondsList(atom);
for (int i = 0; i < bonds.size(); i++) {
IAtom connectedAtom = ((IBond)bonds.get(i)).getConnectedAtom(atom);
if (connectedAtom.getFlag(CDKConstants.ISPLACED) & !connectedAtom.getSymbol().equals("H")) {
if (connectedAtom.getFlag(CDKConstants.ISPLACED) && !connectedAtom.getSymbol().equals("H")) {
return connectedAtom;
}
}
Expand Down Expand Up @@ -551,7 +552,7 @@ public IAtomContainer getPlacedHeavyAtoms(IAtomContainer molecule, IAtom atom) {
IAtom connectedAtom = null;
for (int i = 0; i < bonds.size(); i++) {
connectedAtom = ((IBond)bonds.get(i)).getConnectedAtom(atom);
if (connectedAtom.getFlag(CDKConstants.ISPLACED) & !(connectedAtom.getSymbol().equals("H"))) {
if (connectedAtom.getFlag(CDKConstants.ISPLACED) && !(connectedAtom.getSymbol().equals("H"))) {
connectedAtoms.addAtom(connectedAtom);
}
}
Expand Down Expand Up @@ -597,12 +598,64 @@ private IAtomContainer getAllPlacedAtoms(IAtomContainer molecule) {
*/
public boolean allHeavyAtomsPlaced(IAtomContainer ac) {
for (int i = 0; i < ac.getAtomCount(); i++) {
if (!ac.getAtom(i).getFlag(CDKConstants.ISPLACED) & !(ac.getAtom(i).getSymbol().equals("H"))) {
if (!ac.getAtom(i).getFlag(CDKConstants.ISPLACED) && !(ac.getAtom(i).getSymbol().equals("H"))) {
return false;
}
}
return true;
}

/**
* Determine if the atom is non-hydrogen and has not been placed.
*
* @param atom The atom to be checked
* @return True if the atom is non-hydrogen and has not been placed
*/
boolean isUnplacedHeavyAtom(IAtom atom) {
return (!atom.getFlag(CDKConstants.ISPLACED) && isHeavyAtom(atom));
}

/**
* Determine if the atom is non-hydrogen and has been placed.
*
* @param atom The atom to be checked
* @return True if the atom is non-hydrogen and has been placed
*/
boolean isPlacedHeavyAtom(IAtom atom) {
return atom.getFlag(CDKConstants.ISPLACED) && isHeavyAtom(atom);
}

/**
* Determine if the atom is non-hydrogen and is aliphatic.
*
* @param atom The atom to be checked
* @return True if the atom is non-hydrogen and is aliphatic
*/
boolean isAliphaticHeavyAtom(IAtom atom) {
return atom.getFlag(CDKConstants.ISALIPHATIC) && isHeavyAtom(atom);
}

/**
* Determine if the atom is non-hydrogen and is in a ring.
* Ring membership is determined from a property flag only, rather than a ring
* membership test
*
* @param atom The atom to be checked
* @return True if the atom is non-hydrogen and is in a ring
*/
boolean isRingHeavyAtom(IAtom atom) {
return atom.getFlag(CDKConstants.ISINRING) && isHeavyAtom(atom);
}

/**
* Determine if the atom is heavy (non-hydrogen).
*
* @param atom The atom to be checked
* @return True if the atom is non-hydrogen
*/
boolean isHeavyAtom(IAtom atom) {
return !atom.getSymbol().equals("H");
}
}


@@ -1,4 +1,5 @@
/* Copyright (C) 2005-2007 Christian Hoppe <chhoppe@users.sf.net>
* 2014 Mark B Vine (orcid:0000-0002-7794-0426)
*
* Contact: cdk-devel@list.sourceforge.net
*
Expand All @@ -22,6 +23,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

Expand All @@ -40,7 +42,11 @@
import org.openscience.cdk.silent.AtomContainer;
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;


Expand All @@ -54,6 +60,22 @@ public class AtomPlacer3DTest extends CDKTestCase{

boolean standAlone = false;

@BeforeClass
public static void setUpClass() throws Exception {
}

@AfterClass
public static void tearDownClass() throws Exception {
}

@Before
public void setUp() throws Exception {
}

@After
public void tearDown() throws Exception {
}


/**
* Sets the standAlone attribute
Expand Down Expand Up @@ -224,6 +246,110 @@ public void testGeometricCenterAllPlacedAtoms_IAtomContainer() throws Exception
Assert.assertEquals(4.68, center.y,0.01);
Assert.assertEquals(0.35, center.z,0.01);
}

@Test
public void testIsUnplacedHeavyAtom() {

IAtomContainer ac = makeMethaneWithExplicitHydrogens();
IAtom carbon = ac.getAtom(0);
IAtom hydrogen = ac.getAtom(1);
AtomPlacer3D placer = new AtomPlacer3D();

boolean result = false;
result = placer.isUnplacedHeavyAtom(carbon);
Assert.assertTrue(result);
result = placer.isUnplacedHeavyAtom(hydrogen);
Assert.assertFalse(result);

carbon.setFlag(CDKConstants.ISPLACED, true);
result = placer.isUnplacedHeavyAtom(carbon);
Assert.assertFalse(result);
hydrogen.setFlag(CDKConstants.ISPLACED, true);
result = placer.isUnplacedHeavyAtom(hydrogen);
Assert.assertFalse(result);
}

@Test
public void testIsPlacedHeavyAtom() {

IAtomContainer ac = makeMethaneWithExplicitHydrogens();
IAtom carbon = ac.getAtom(0);
IAtom hydrogen = ac.getAtom(1);
AtomPlacer3D placer = new AtomPlacer3D();

boolean result = false;
result = placer.isPlacedHeavyAtom(carbon);
Assert.assertFalse(result);
result = placer.isPlacedHeavyAtom(hydrogen);
Assert.assertFalse(result);

carbon.setFlag(CDKConstants.ISPLACED, true);
result = placer.isPlacedHeavyAtom(carbon);
Assert.assertTrue(result);
hydrogen.setFlag(CDKConstants.ISPLACED, true);
result = placer.isPlacedHeavyAtom(hydrogen);
Assert.assertFalse(result);
}


@Test
public void testIsAliphaticHeavyAtom() {

IAtomContainer ac = makeMethaneWithExplicitHydrogens();
IAtom carbon = ac.getAtom(0);
IAtom hydrogen = ac.getAtom(1);
AtomPlacer3D placer = new AtomPlacer3D();

boolean result = false;
result = placer.isAliphaticHeavyAtom(carbon);
Assert.assertFalse(result);
result = placer.isAliphaticHeavyAtom(hydrogen);
Assert.assertFalse(result);

carbon.setFlag(CDKConstants.ISALIPHATIC, true);
result = placer.isAliphaticHeavyAtom(carbon);
Assert.assertTrue(result);
hydrogen.setFlag(CDKConstants.ISALIPHATIC, true);
result = placer.isAliphaticHeavyAtom(hydrogen);
Assert.assertFalse(result);
}

@Test
public void testIsRingHeavyAtom() {

IAtomContainer ac = makeMethaneWithExplicitHydrogens();
IAtom carbon = ac.getAtom(0);
IAtom hydrogen = ac.getAtom(1);
AtomPlacer3D placer = new AtomPlacer3D();

boolean result = false;
result = placer.isRingHeavyAtom(carbon);
Assert.assertFalse(result);
result = placer.isRingHeavyAtom(hydrogen);
Assert.assertFalse(result);

carbon.setFlag(CDKConstants.ISINRING, true);
result = placer.isRingHeavyAtom(carbon);
Assert.assertTrue(result);
hydrogen.setFlag(CDKConstants.ISINRING, true);
result = placer.isRingHeavyAtom(hydrogen);
Assert.assertFalse(result);
}

@Test
public void testIsHeavyAtom() {

IAtomContainer ac = makeMethaneWithExplicitHydrogens();
IAtom carbon = ac.getAtom(0);
IAtom hydrogen = ac.getAtom(1);
AtomPlacer3D placer = new AtomPlacer3D();

boolean result = false;
result = placer.isHeavyAtom(carbon);
Assert.assertTrue(result);
result = placer.isHeavyAtom(hydrogen);
Assert.assertFalse(result);
}
}


0 comments on commit 31e196e

Please sign in to comment.