Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Upgrade ISAROMATIC and ISINRING flags to first class methods for acce…
…ss and mutation.
  • Loading branch information
johnmay committed Oct 10, 2015
1 parent ae42093 commit 98ae764
Show file tree
Hide file tree
Showing 20 changed files with 274 additions and 35 deletions.
Expand Up @@ -652,7 +652,7 @@ private boolean atLeastTwoNeighborsAreSp2(IAtom atom, IAtomContainer atomContain
} else if (countAttachedDoubleBonds(atomContainer, nextAtom) > 0) {
// OK, it's SP2
count++;
} else if (atomContainer.getBond(atom, nextAtom).getFlag(CDKConstants.ISAROMATIC)) {
} else if (atomContainer.getBond(atom, nextAtom).isAromatic()) {
// two aromatic bonds indicate sp2
count++;
} // OK, not SP2
Expand Down Expand Up @@ -944,7 +944,7 @@ private boolean isSingleHeteroAtom(IAtom atom, IAtomContainer container) {

for (IAtom atom1 : connected) {

boolean aromatic = container.getBond(atom, atom1).getFlag(CDKConstants.ISAROMATIC);
boolean aromatic = container.getBond(atom, atom1).isAromatic();

// ignoring non-aromatic bonds
if (!aromatic) continue;
Expand All @@ -955,7 +955,7 @@ private boolean isSingleHeteroAtom(IAtom atom, IAtomContainer container) {
// check the second sphere
for (IAtom atom2 : container.getConnectedAtomsList(atom1)) {

if (atom2 != atom && container.getBond(atom1, atom2).getFlag(CDKConstants.ISAROMATIC)
if (atom2 != atom && container.getBond(atom1, atom2).isAromatic()
&& !"C".equals(atom2.getSymbol())) {
return false;
}
Expand Down Expand Up @@ -2379,7 +2379,7 @@ private int countAttachedSingleBonds(IAtomContainer atomContainer, IAtom atom) {
private boolean hasAromaticBond(IAtomContainer container, IAtom atom) {
List<IBond> neighbors = container.getConnectedBondsList(atom);
for (IBond bond : neighbors) {
if (bond.getFlag(CDKConstants.ISAROMATIC)) return true;
if (bond.isAromatic()) return true;
}
return false;
}
Expand Down
24 changes: 24 additions & 0 deletions base/data/src/main/java/org/openscience/cdk/Atom.java
Expand Up @@ -371,6 +371,30 @@ public boolean compare(Object object) {
return false;
}

/** {@inheritDoc} */
@Override
public boolean isAromatic() {
return getFlag(CDKConstants.ISAROMATIC);
}

/** {@inheritDoc} */
@Override
public void setIsAromatic(boolean arom) {
setFlag(CDKConstants.ISAROMATIC, arom);
}

/** {@inheritDoc} */
@Override
public boolean isInRing() {
return getFlag(CDKConstants.ISINRING);
}

/** {@inheritDoc} */
@Override
public void setIsInRing(boolean ring) {
setFlag(CDKConstants.ISINRING, ring);
}

/**
* Returns a one line string representation of this Atom.
* Methods is conform RFC #9.
Expand Down
24 changes: 24 additions & 0 deletions base/data/src/main/java/org/openscience/cdk/Bond.java
Expand Up @@ -475,6 +475,30 @@ public boolean isConnectedTo(IBond bond) {
return false;
}

/** {@inheritDoc} */
@Override
public boolean isAromatic() {
return getFlag(CDKConstants.ISAROMATIC);
}

/** {@inheritDoc} */
@Override
public void setIsAromatic(boolean arom) {
setFlag(CDKConstants.ISAROMATIC, arom);
}

/** {@inheritDoc} */
@Override
public boolean isInRing() {
return getFlag(CDKConstants.ISINRING);
}

/** {@inheritDoc} */
@Override
public void setIsInRing(boolean ring) {
setFlag(CDKConstants.ISINRING, ring);
}

/**
* Clones this bond object, including clones of the atoms between which the
* bond is defined.
Expand Down
Expand Up @@ -140,6 +140,43 @@ public interface IAtom extends IAtomType {
*/
public Integer getStereoParity();

/**
* Access whether this atom has been marked as aromatic. The default
* value is false and you must explicitly perceive aromaticity with
* one of the available models.
*
* @return aromatic status
* @see #getFlag(int)
* @see org.openscience.cdk.aromaticity.Aromaticity
*/
boolean isAromatic();

/**
* Mark this atom as being aromatic.
*
* @param arom aromatic status
* @see #setFlag(int, boolean)
*/
void setIsAromatic(boolean arom);

/**
* Access whether this atom has been flagged as in a ring. The default
* value is false and you must explicitly find rings first.
*
* @return ring status
* @see #getFlag(int)
* @see @see org.openscience.cdk.graph.RingFinder
*/
boolean isInRing();

/**
* Mark this atom as being in a ring.
*
* @param ring ring status
* @see #setFlag(int, boolean)
*/
void setIsInRing(boolean ring);

/**
* @inheritDoc
*/
Expand Down
Expand Up @@ -247,6 +247,43 @@ public enum Stereo {
*/
public boolean isConnectedTo(IBond bond);

/**
* Access whether this bond has been marked as aromatic. The default
* value is false and you must explicitly perceive aromaticity with
* one of the available models.
*
* @return aromatic status
* @see #getFlag(int)
* @see org.openscience.cdk.aromaticity.Aromaticity
*/
boolean isAromatic();

/**
* Mark this bond as being aromatic.
*
* @param arom aromatic status
* @see #setFlag(int, boolean)
*/
void setIsAromatic(boolean arom);

/**
* Access whether this bond has been flagged as in a ring. The default
* value is false and you must explicitly find rings first.
*
* @return ring status
* @see #getFlag(int)
* @see @see org.openscience.cdk.graph.RingFinder
*/
boolean isInRing();

/**
* Mark this bond as being in a ring.
*
* @param ring ring status
* @see #setFlag(int, boolean)
*/
void setIsInRing(boolean ring);

/** @inheritDoc */
@Override
public IBond clone() throws CloneNotSupportedException;
Expand Down
Expand Up @@ -667,6 +667,30 @@ public Integer getValency() {
return this.electronValency;
}

/** {@inheritDoc} */
@Override
public boolean isAromatic() {
return getFlag(CDKConstants.ISAROMATIC);
}

/** {@inheritDoc} */
@Override
public void setIsAromatic(boolean arom) {
setFlag(CDKConstants.ISAROMATIC, arom);
}

/** {@inheritDoc} */
@Override
public boolean isInRing() {
return getFlag(CDKConstants.ISINRING);
}

/** {@inheritDoc} */
@Override
public void setIsInRing(boolean ring) {
setFlag(CDKConstants.ISINRING, ring);
}

@Override
public IAtom clone() throws CloneNotSupportedException {
// XXX: clone always dodgy
Expand Down
Expand Up @@ -480,6 +480,30 @@ public Integer getElectronCount() {
return this.electronCount;
}

/** {@inheritDoc} */
@Override
public boolean isAromatic() {
return getFlag(CDKConstants.ISAROMATIC);
}

/** {@inheritDoc} */
@Override
public void setIsAromatic(boolean arom) {
setFlag(CDKConstants.ISAROMATIC, arom);
}

/** {@inheritDoc} */
@Override
public boolean isInRing() {
return getFlag(CDKConstants.ISINRING);
}

/** {@inheritDoc} */
@Override
public void setIsInRing(boolean ring) {
setFlag(CDKConstants.ISINRING, ring);
}

/**
* Sets the number of electrons in this bond
* @param electronCount The number of electrons in this electron container.
Expand Down
24 changes: 24 additions & 0 deletions base/silent/src/main/java/org/openscience/cdk/silent/Atom.java
Expand Up @@ -367,6 +367,30 @@ public boolean compare(Object object) {
return false;
}

/** {@inheritDoc} */
@Override
public boolean isAromatic() {
return getFlag(CDKConstants.ISAROMATIC);
}

/** {@inheritDoc} */
@Override
public void setIsAromatic(boolean arom) {
setFlag(CDKConstants.ISAROMATIC, arom);
}

/** {@inheritDoc} */
@Override
public boolean isInRing() {
return getFlag(CDKConstants.ISINRING);
}

/** {@inheritDoc} */
@Override
public void setIsInRing(boolean ring) {
setFlag(CDKConstants.ISINRING, ring);
}

/**
* Returns a one line string representation of this Atom.
* Methods is conform RFC #9.
Expand Down
24 changes: 24 additions & 0 deletions base/silent/src/main/java/org/openscience/cdk/silent/Bond.java
Expand Up @@ -468,6 +468,30 @@ public boolean isConnectedTo(IBond bond) {
return false;
}

/** {@inheritDoc} */
@Override
public boolean isAromatic() {
return getFlag(CDKConstants.ISAROMATIC);
}

/** {@inheritDoc} */
@Override
public void setIsAromatic(boolean arom) {
setFlag(CDKConstants.ISAROMATIC, arom);
}

/** {@inheritDoc} */
@Override
public boolean isInRing() {
return getFlag(CDKConstants.ISINRING);
}

/** {@inheritDoc} */
@Override
public void setIsInRing(boolean ring) {
setFlag(CDKConstants.ISINRING, ring);
}

/**
* Clones this bond object, including clones of the atoms between which the
* bond is defined.
Expand Down
Expand Up @@ -238,15 +238,15 @@ public boolean apply(IAtomContainer molecule) throws CDKException {
// clear existing flags
molecule.setFlag(ISAROMATIC, false);
for (IBond bond : molecule.bonds())
bond.setFlag(ISAROMATIC, false);
bond.setIsAromatic(false);
for (IAtom atom : molecule.atoms())
atom.setFlag(ISAROMATIC, false);
atom.setIsAromatic(false);

// set the new flags
for (final IBond bond : bonds) {
bond.setFlag(ISAROMATIC, true);
bond.getAtom(0).setFlag(ISAROMATIC, true);
bond.getAtom(1).setFlag(ISAROMATIC, true);
bond.setIsAromatic(true);
bond.getAtom(0).setIsAromatic(true);
bond.getAtom(1).setIsAromatic(true);
}

molecule.setFlag(ISAROMATIC, !bonds.isEmpty());
Expand Down
Expand Up @@ -102,7 +102,7 @@ public static void kekulize(final IAtomContainer ac) throws CDKException {

// propegate bond order information from the matching
for (final IBond bond : ac.bonds()) {
if (bond.getOrder() == UNSET && bond.getFlag(ISAROMATIC)) bond.setOrder(SINGLE);
if (bond.getOrder() == UNSET && bond.isAromatic()) bond.setOrder(SINGLE);
}
for (int v = available.nextSetBit(0); v >= 0; v = available.nextSetBit(v + 1)) {
final int w = matching.other(v);
Expand Down
Expand Up @@ -27,6 +27,7 @@
import javax.vecmath.Point2d;
import javax.vecmath.Point3d;

import org.openscience.cdk.CDKConstants;
import org.openscience.cdk.interfaces.IAtom;
import org.openscience.cdk.interfaces.IChemObjectBuilder;
import org.openscience.cdk.interfaces.IChemObjectChangeEvent;
Expand Down Expand Up @@ -579,4 +580,26 @@ public IChemObjectBuilder getBuilder() {
return null;
}

/** {@inheritDoc} */
@Override
public boolean isAromatic() {
return false;
}

/** {@inheritDoc} */
@Override
public void setIsAromatic(boolean arom) {
}

/** {@inheritDoc} */
@Override
public boolean isInRing() {
return false;
}

/** {@inheritDoc} */
@Override
public void setIsInRing(boolean ring) {
}

}

0 comments on commit 98ae764

Please sign in to comment.