Skip to content

Commit

Permalink
Descriptors that need a clone to avoid modifying the input.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Jan 3, 2018
1 parent 7ea64b4 commit 3e2beea
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

package org.openscience.cdk.qsar;

import org.openscience.cdk.interfaces.IAtomContainer;

/**
* A super class for molecular descriptors allowing default implementations for
* interface methods.
Expand All @@ -33,4 +35,12 @@
*/
public abstract class AbstractMolecularDescriptor extends AbstractDescriptor implements IMolecularDescriptor {

protected static IAtomContainer clone(IAtomContainer mol) {
try {
return mol.clone();
} catch (CloneNotSupportedException e) {
throw new IllegalStateException("Could not clone AtomContainer!");
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public DescriptorValue calculate(IAtomContainer atomContainer) {
throw new IllegalStateException("descriptor is not initalised, invoke 'initalise' first");
}

atomContainer = clone(atomContainer); // don't mod original

// do aromaticity detection
if (this.checkAromaticity) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ public DescriptorValue calculate(IAtomContainer atomContainer) {
throw new IllegalStateException("descriptor is not initalised, invoke 'initalise' first");
}

atomContainer = clone(atomContainer);

try {
int count = 0;
for (SMARTSQueryTool tool : tools) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public FMFDescriptor() {}
*/
@Override
public DescriptorValue calculate(IAtomContainer container) {

container = clone(container); // don't mod original

MurckoFragmenter fragmenter = new MurckoFragmenter(true, 3);
DoubleResult result;
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ public String[] getDescriptorNames() {
*/
@Override
public DescriptorValue calculate(IAtomContainer ac) {
ac = clone(ac); // don't mod original
int rotatableBondsCount = 0;
int degree0;
int degree1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public String[] getDescriptorNames() {
*/
@Override
public DescriptorValue calculate(IAtomContainer mol) {

mol = clone(mol); // don't mod original
int lipinskifailures = 0;

IMolecularDescriptor xlogP = new XLogPDescriptor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ private DescriptorValue getDummyDescriptorValue(Exception e) {
public DescriptorValue calculate(IAtomContainer atomContainer) {
double volume;
try {
volume = VABCVolume.calculate(atomContainer);
// clone: don't mod original
volume = VABCVolume.calculate(clone(atomContainer));
} catch (CDKException exception) {
return getDummyDescriptorValue(exception);
}
Expand Down

0 comments on commit 3e2beea

Please sign in to comment.