Skip to content

Commit

Permalink
added mode to retrieve single SSS matches only
Browse files Browse the repository at this point in the history
  • Loading branch information
thsa committed Nov 27, 2023
1 parent e9be8d1 commit 48dd584
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
24 changes: 21 additions & 3 deletions src/main/java/com/actelion/research/chem/StructureSearch.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class StructureSearch {
private volatile StructureSearchDataSource mDataSource;
private volatile StructureSearchController mSearchController;
private volatile ProgressController mProgressController;
private volatile StereoMolecule[] mQueryFragment;
private volatile StereoMolecule[] mQueryFragment,mDoubleQueryFragment;
private volatile ByteArrayComparator mIDCodeComparator;
private volatile DescriptorHandler mDescriptorHandler;
private volatile Object[] mQueryDescriptor;
Expand Down Expand Up @@ -156,6 +156,15 @@ public int[] start() {
mQueryFragment[i] = new IDCodeParser(false).getCompactMolecule(mSpecification.getIDCode(i));
mQueryFragment[i].ensureHelperArrays(Molecule.cHelperParities);
}
if (mSpecification.isSingleMatchOnly()) {
mDoubleQueryFragment = new StereoMolecule[queryStructureCount];
for (int i=0; i<queryStructureCount; i++) {
mDoubleQueryFragment[i] = new StereoMolecule(mQueryFragment[i].getAtoms(), mQueryFragment[i].getBonds());
mDoubleQueryFragment[i].addMolecule(mQueryFragment[i]);
mDoubleQueryFragment[i].addMolecule(mQueryFragment[i]);
mDoubleQueryFragment[i].ensureHelperArrays(Molecule.cHelperParities);
}
}
}
else {
final String descriptorShortName = mSpecification.getDescriptorShortName();
Expand Down Expand Up @@ -310,8 +319,17 @@ public void run() {
for (int i=0; i<mQueryFragment.length; i++) {
mSSSearcher.setFragment(mQueryFragment[i], (long[])mQueryDescriptor[i]);
if (mSSSearcher.isFragmentInMolecule()) {
isMatch = true;
break;
if (mSpecification.isSingleMatchOnly()) {
mSSSearcher.setFragment(mDoubleQueryFragment[i], (long[])mQueryDescriptor[i]);
if (!mSSSearcher.isFragmentInMolecule()) {
isMatch = true;
break;
}
}
else {
isMatch = true;
break;
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public class StructureSearchSpecification implements Serializable {
public static final int TYPE_TAUTOMER_NO_STEREO = 0x000006;
public static final int TYPE_BACKBONE_NO_STEREO = 0x000007;

public static final int MODE_LARGEST_FRAGMENT_ONLY = 0x000100;
public static final int MODE_LARGEST_FRAGMENT_ONLY = 0x000100;
public static final int MODE_SINGLE_MATCH_ONLY = 0x000200;

private int mSearchType;
private byte[][] mIDCode;
Expand Down Expand Up @@ -178,16 +179,36 @@ public boolean isLargestFragmentOnly() {
return (mSearchType & MODE_LARGEST_FRAGMENT_ONLY) != 0;
}

public boolean isSingleMatchOnly() {
return (mSearchType & MODE_SINGLE_MATCH_ONLY) != 0;
}

public void removeDescriptors() {
mDescriptor = null;
}

/**
*
* @param b
*/
public void setLargestFragmentOnly(boolean b) {
mSearchType &= ~MODE_LARGEST_FRAGMENT_ONLY;
if (b)
mSearchType |= MODE_LARGEST_FRAGMENT_ONLY;
}

/**
* In case of a substructure search, as default a molecule is considered a match if the query
* structure is found once or multiple times. To consider only single matches a match, call this
* method with argument true.
* @param b
*/
public void setSingleMatchOnly(boolean b) {
mSearchType &= ~MODE_SINGLE_MATCH_ONLY;
if (b)
mSearchType |= MODE_SINGLE_MATCH_ONLY;
}

public String getDescriptorShortName() {
return mDescriptorShortName;
}
Expand Down

0 comments on commit 48dd584

Please sign in to comment.