Code Monkey home page Code Monkey logo

Comments (2)

mcs07 avatar mcs07 commented on August 27, 2024

If you want similarities between compounds in an SDF file, I would recommend generating fingerprints and calculating similarities locally using RDKit (or OpenBabel, CDK, etc.). Something like:

mols = Chem.SDMolSupplier('myfile.sdf')
fp1 = AllChem.GetMorganFingerprint(mols[0], 2)
fp2 = AllChem.GetMorganFingerprint(mols[1], 2)
DataStructs.TanimotoSimilarity(fp1, fp2)

But if you specifically want to use PubChem fingerprints you can do something like this with PubChemPy:

def tanimoto(compound1, compound2):
    fp1 = int(compound1.fingerprint, 16)
    fp2 = int(compound2.fingerprint, 16)
    fp1_count = bin(fp1).count('1')
    fp2_count = bin(fp2).count('1')
    both_count = bin(fp1 & fp2).count('1')
    return float(both_count) / (fp1_count + fp2_count - both_count)

I added a more complete example here: https://github.com/mcs07/PubChemPy/blob/master/examples/Chemical%20fingerprints%20and%20similarity.ipynb

from pubchempy.

beyondpie avatar beyondpie commented on August 27, 2024

Great !
Yes, I also use RDKit. In this part, I only want to get the PubChem similarities.
Now I see, by compound.fingerprint in your package, I can not only get the similarities, but also the PubChem fingerprints ~
Thanks a lot !
Songpeng

from pubchempy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.