com.actelion.research.chem.descriptor.DescriptorHandlerReactionFP Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of openchemlib Show documentation
Show all versions of openchemlib Show documentation
Open Source Chemistry Library
/*
* Copyright (c) 1997 - 2016
* Actelion Pharmaceuticals Ltd.
* Gewerbestrasse 16
* CH-4123 Allschwil, Switzerland
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* 3. Neither the name of the the copyright holder nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
package com.actelion.research.chem.descriptor;
import com.actelion.research.chem.Canonizer;
import com.actelion.research.chem.Molecule;
import com.actelion.research.chem.StereoMolecule;
import com.actelion.research.chem.reaction.Reaction;
import com.actelion.research.util.BurtleHasher;
import java.util.Arrays;
public class DescriptorHandlerReactionFP extends AbstractDescriptorHandlerLongFP {
public static final String cVersion = "1.0.0";
public static final int REACTION_CENTER_LONG_COUNT = 8;
public static final float REACTION_CENTER_WEIGHT = 0.8f; // the percentage of reaction center similarity to contribute to the total similarity
public static final float PERIPHERY_WEIGHT = 1f - REACTION_CENTER_WEIGHT;
private static final int SPHERE_COUNT = 5;
private static final int HASH_BITS = 10;
private static final int HASH_INIT = 13;
private static final int DESCRIPTOR_SIZE = (1 << HASH_BITS);
private static DescriptorHandlerReactionFP sDefaultInstance;
public static DescriptorHandlerReactionFP getDefaultInstance() {
if (sDefaultInstance == null) {
synchronized(DescriptorHandlerReactionFP.class) {
sDefaultInstance = new DescriptorHandlerReactionFP();
}
}
return sDefaultInstance;
}
public DescriptorInfo getInfo() {
return DescriptorConstants.DESCRIPTOR_ReactionFP;
}
public String getVersion() {
return DescriptorConstants.DESCRIPTOR_ReactionFP.version;
}
public long[] createDescriptor(Reaction rxn) {
if (rxn == null)
return null;
boolean[] isReactionCenterMapNo = rxn.getReactionCenterMapNos();
if (isReactionCenterMapNo == null)
return FAILED_OBJECT;
final int len = DESCRIPTOR_SIZE / Long.SIZE;
long[] data = new long[len];
//System.out.println("mol\tisProduct\tatom\tsphere\tisRC\thash\tindex\tbit\tidcode");
for (int m=0; m= rxn.getReactants())
idcode = idcode.concat("P");
// For reaction center atoms smaller fragments have higher weights, which is achieved by a higher number of representing bits
int weight = isReactionCenterAtom[rootAtom] ? SPHERE_COUNT - sphere : 1;
for (int i=0; i= rxn.getReactants())+"\t"+rootAtom+"\t"+sphere+"\t"+isReactionCenterAtom[rootAtom]+"\t"+h+"\t"+index+"\t"+(h % Long.SIZE)+"\t"+idcode);
}
}
}
}
return data;
// return (descriptor == null) ? FAILED_OBJECT : descriptor;
}
public float getSimilarity(long[] o1, long[] o2) {
if (o1 == null
|| o2 == null
|| o1.length == 0
|| o2.length == 0)
return 0.0f;
float reactionCenterSimilarity = getSimilarityTanimoto(o1, o2, 0, REACTION_CENTER_LONG_COUNT);
float nonReactionCenterSimilarity = getSimilarityTanimoto(o1, o2, REACTION_CENTER_LONG_COUNT, o1.length);
return REACTION_CENTER_WEIGHT * reactionCenterSimilarity + PERIPHERY_WEIGHT * nonReactionCenterSimilarity;
}
public float getReactionCenterSimilarity(long[] o1, long[] o2) {
if (o1 == null
|| o2 == null
|| o1.length == 0
|| o2.length == 0)
return 0.0f;
return getSimilarityTanimoto(o1, o2, 0, REACTION_CENTER_LONG_COUNT);
}
public float getPeripherySimilarity(long[] o1, long[] o2) {
if (o1 == null
|| o2 == null
|| o1.length == 0
|| o2.length == 0)
return 0.0f;
return getSimilarityTanimoto(o1, o2, REACTION_CENTER_LONG_COUNT, o1.length);
}
public static float getSimilarityTanimoto(final long[] index1, final long[] index2, int i1, int i2) {
int sharedKeys = 0;
int allKeys = 0;
for (int i=i1; i getThreadSafeCopy() {
return this;
}
}