Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
*~
__pychache__/
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
*.pyc
7 changes: 7 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
include README.md
include LICENSE.txt
recursive-include espsim *.pt
recursive-include espsim/testfiles *.mol *.mol2 *.sdf
recursive-include benchmarks *.ipynb
recursive-include scripts *.py *.ipynb
recursive-include workshop *.ipynb *.md
49 changes: 25 additions & 24 deletions espsim/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from argparse import Namespace
import os
import contextlib
import pkg_resources
from importlib.resources import files, as_file
import warnings
import logging

Expand Down Expand Up @@ -144,29 +144,30 @@ def mlCharges(mols):
#MUST use mols with hydrogens!
smiles = [Chem.MolToSmiles(mol) for mol in mols]

path = pkg_resources.resource_filename(__name__, 'QM_137k.pt')
args = Namespace(batch_size=50, checkpoint_dir=None, checkpoint_path=path, checkpoint_paths=[path], cuda=False, features_generator=None, features_path=None, gpu=None, max_data_size=None, no_features_scaling=False, preds_path=None, test_path=None, use_compound_names=False)

with open(os.devnull, 'w') as devnull:
with contextlib.redirect_stdout(devnull):
test_preds, test_smiles = make_predictions(args, smiles=smiles)
n_atoms, n_bonds = zip(*[num_atoms_bonds(x) for x in smiles])
partial_charge = test_preds[0]
partial_charge = np.split(partial_charge.flatten(), np.cumsum(np.array(n_atoms)))[:-1]

charges=[]
for i,mol in enumerate(mols):
try:
reorder_list = get_reorder_list(mol)
charges.append([partial_charge[i][reorder_list[x]] for x in range(mol.GetNumAtoms())])
except ValueError:
#Could not get prediction, default to Gasteiger
print("Warning: could not obtain prediction, defaulting to Gasteiger charges for one molecule")
AllChem.ComputeGasteigerCharges(mol)
charges.append([a.GetDoubleProp('_GasteigerCharge') for a in mol.GetAtoms()])


return charges
model_file = files('espsim').joinpath('QM_137k.pt')
with as_file(model_file) as path:
args = Namespace(batch_size=50, checkpoint_dir=None, checkpoint_path=str(path), checkpoint_paths=[str(path)], cuda=False, features_generator=None, features_path=None, gpu=None, max_data_size=None, no_features_scaling=False, preds_path=None, test_path=None, use_compound_names=False)

with open(os.devnull, 'w') as devnull:
with contextlib.redirect_stdout(devnull):
test_preds, test_smiles = make_predictions(args, smiles=smiles)
n_atoms, n_bonds = zip(*[num_atoms_bonds(x) for x in smiles])
partial_charge = test_preds[0]
partial_charge = np.split(partial_charge.flatten(), np.cumsum(np.array(n_atoms)))[:-1]

charges=[]
for i,mol in enumerate(mols):
try:
reorder_list = get_reorder_list(mol)
charges.append([partial_charge[i][reorder_list[x]] for x in range(mol.GetNumAtoms())])
except ValueError:
#Could not get prediction, default to Gasteiger
print("Warning: could not obtain prediction, defaulting to Gasteiger charges for one molecule")
AllChem.ComputeGasteigerCharges(mol)
charges.append([a.GetDoubleProp('_GasteigerCharge') for a in mol.GetAtoms()])


return charges

except ImportError:
def mlCharges(mols):
Expand Down
1 change: 1 addition & 0 deletions espsim/testfiles/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Test data files for espsim package."""
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
65 changes: 65 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
[build-system]
requires = ["setuptools>=45", "wheel", "setuptools-scm[toml]>=6.2"]
build-backend = "setuptools.build_meta"

[project]
name = "espsim"
version = "0.0.2"
description = "Scoring of shape and ESP similarity with RDKit"
readme = "README.md"
license = {text = "MIT"}
authors = [
{name = "Esther Heid", email = "eheid@mit.edu"}
]
classifiers = [
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"License :: OSI Approved :: MIT License",
"Operating System :: OS Independent"
]
keywords = [
"chemistry",
"electrostatic potential",
"shape",
"similarity",
"RDKit"
]
requires-python = ">=3.9"
dependencies = [
"rdkit>=2023.03",
"torch>=2.0",
"numpy<2",
"scikit-learn>=1.0",
"scipy>=1.8",
"matplotlib>=3.5",
"joblib>=1.2",
"tqdm>=4.6",
"py3dmol>=0.8",
]

[project.optional-dependencies]
dev = [
"jupyter>=1.0",
"pytest>=7.0",
"black>=23.0",
"flake8>=4.0",
"mypy>=1.0",
]
chemprop = [
"chemprop-atom-bond @ git+https://github.com/hesther/chemprop-atom-bond.git",
]
psi4 = [
"psi4>=1.5",
"resp>=1.0",
]

[project.urls]
Homepage = "https://github.com/hesther/espsim"
Repository = "https://github.com/hesther/espsim"
Issues = "https://github.com/hesther/espsim/issues"

[tool.setuptools]
packages = ["espsim", "espsim.testfiles"]
include-package-data = true
34 changes: 22 additions & 12 deletions scripts/test_esp_function.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,32 @@
from espsim import GetEspSim, readMolFile, readMol2File, readSdfFile
from importlib.resources import files, as_file

# Get paths to test files from package data
testfiles = files('espsim.testfiles')

#The following block of code reads in prealigned molecules in mol format and calculates their ESP similarity:
mol1=readMolFile("scripts/prbmol1.mol")
mol2=readMolFile("scripts/refmol1.mol")
sim_esp=GetEspSim(mol1,mol2)
print("%15s %5.2f" % ("ESP similarity (mols read from mol file):",sim_esp))
with as_file(testfiles.joinpath('prbmol1.mol')) as prbmol_path, \
as_file(testfiles.joinpath('refmol1.mol')) as refmol_path:
mol1=readMolFile(str(prbmol_path))
mol2=readMolFile(str(refmol_path))
sim_esp=GetEspSim(mol1,mol2)
print("%15s %5.2f" % ("ESP similarity (mols read from mol file):",sim_esp))


#The following block of code reads in prealigned molecules in mol2 format with custom charges and calculates their ESP similarity:
mol1,charge1=readMol2File("scripts/prbmol1.mol2")
mol2,charge2=readMol2File("scripts/refmol1.mol2")
sim_esp=GetEspSim(mol1,mol2,prbCharge=charge1,refCharge=charge2)
print("%15s %5.2f" % ("ESP similarity (mols read from mol2 file):",sim_esp))
with as_file(testfiles.joinpath('prbmol1.mol2')) as prbmol_path, \
as_file(testfiles.joinpath('refmol1.mol2')) as refmol_path:
mol1,charge1=readMol2File(str(prbmol_path))
mol2,charge2=readMol2File(str(refmol_path))
sim_esp=GetEspSim(mol1,mol2,prbCharge=charge1,refCharge=charge2)
print("%15s %5.2f" % ("ESP similarity (mols read from mol2 file):",sim_esp))


#The following block of code reads in prealigned molecules in sdf format with custom charges as a comma-separated list
#in the SDF file and calculates their ESP similarity:
mol1,charge1=readSdfFile("scripts/prbmol1.sdf")
mol2,charge2=readSdfFile("scripts/refmol1.sdf")
sim_esp=GetEspSim(mol1,mol2,prbCharge=charge1,refCharge=charge2)
print("%15s %5.2f" % ("ESP similarity (mols read from sdf file):",sim_esp))
with as_file(testfiles.joinpath('prbmol1.sdf')) as prbmol_path, \
as_file(testfiles.joinpath('refmol1.sdf')) as refmol_path:
mol1,charge1=readSdfFile(str(prbmol_path))
mol2,charge2=readSdfFile(str(refmol_path))
sim_esp=GetEspSim(mol1,mol2,prbCharge=charge1,refCharge=charge2)
print("%15s %5.2f" % ("ESP similarity (mols read from sdf file):",sim_esp))
31 changes: 0 additions & 31 deletions setup.py

This file was deleted.

31 changes: 31 additions & 0 deletions testfiles/prbmol1.mol
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

RDKit 3D

13 12 0 0 0 0 0 0 0 0999 V2000
-1.0829 -0.6637 -0.5103 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.2977 0.2486 0.4436 C 0 0 0 0 0 0 0 0 0 0 0 0
1.1617 -0.0925 0.4114 C 0 0 0 0 0 0 0 0 0 0 0 0
1.6689 -0.7861 1.3333 O 0 0 0 0 0 0 0 0 0 0 0 0
1.9501 0.3238 -0.6576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.4657 1.5946 0.0836 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.6651 -0.4911 -1.8389 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.9239 -1.7249 -0.2214 H 0 0 0 0 0 0 0 0 0 0 0 0
-2.1739 -0.4579 -0.4169 H 0 0 0 0 0 0 0 0 0 0 0 0
-0.6777 0.0902 1.4808 H 0 0 0 0 0 0 0 0 0 0 0 0
2.9334 0.0857 -0.7021 H 0 0 0 0 0 0 0 0 0 0 0 0
-1.3815 1.8546 0.3656 H 0 0 0 0 0 0 0 0 0 0 0 0
-1.1122 0.3289 -2.1752 H 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 1 0
1 7 1 0
1 8 1 0
1 9 1 0
2 10 1 0
5 11 1 0
6 12 1 0
7 13 1 0
M END

33 changes: 33 additions & 0 deletions testfiles/prbmol1.mol2
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@<TRIPOS>MOLECULE
*****
13 12 0 0 0
SMALL
GASTEIGER

@<TRIPOS>ATOM
1 C -1.0829 -0.6637 -0.5103 C.3 1 UNL1 0.079954117054076082
2 C -0.2977 0.2486 0.4436 C.3 1 UNL1 0.17402774992656297
3 C 1.1617 -0.0925 0.4114 C.2 1 UNL1 0.33445172084859559
4 O 1.6689 -0.7861 1.3333 O.2 1 UNL1 -0.24924322634924762
5 O 1.9501 0.3238 -0.6576 O.3 1 UNL1 -0.47926124554573318
6 O -0.4657 1.5946 0.0836 O.3 1 UNL1 -0.37926397069925832
7 O -0.6651 -0.4911 -1.8389 O.3 1 UNL1 -0.3930474388646486
8 H -0.9239 -1.7249 -0.2214 H 1 UNL1 0.059756578060591724
9 H -2.1739 -0.4579 -0.4169 H 1 UNL1 0.059756578060591724
10 H -0.6777 0.0902 1.4808 H 1 UNL1 0.074910619371653109
11 H 2.9334 0.0857 -0.7021 H 1 UNL1 0.2963731884212602
12 H -1.3815 1.8546 0.3656 H 1 UNL1 0.21139157568550943
13 H -1.1122 0.3289 -2.1752 H 1 UNL1 0.21019375403004686
@<TRIPOS>BOND
1 1 2 1
2 2 3 1
3 3 4 2
4 3 5 1
5 2 6 1
6 1 7 1
7 1 8 1
8 1 9 1
9 2 10 1
10 5 11 1
11 6 12 1
12 7 13 1
34 changes: 34 additions & 0 deletions testfiles/prbmol1.sdf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

RDKit 3D

13 12 0 0 0 0 0 0 0 0999 V2000
-1.0829 -0.6637 -0.5103 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.2977 0.2486 0.4436 C 0 0 0 0 0 0 0 0 0 0 0 0
1.1617 -0.0925 0.4114 C 0 0 0 0 0 0 0 0 0 0 0 0
1.6689 -0.7861 1.3333 O 0 0 0 0 0 0 0 0 0 0 0 0
1.9501 0.3238 -0.6576 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.4657 1.5946 0.0836 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.6651 -0.4911 -1.8389 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.9239 -1.7249 -0.2214 H 0 0 0 0 0 0 0 0 0 0 0 0
-2.1739 -0.4579 -0.4169 H 0 0 0 0 0 0 0 0 0 0 0 0
-0.6777 0.0902 1.4808 H 0 0 0 0 0 0 0 0 0 0 0 0
2.9334 0.0857 -0.7021 H 0 0 0 0 0 0 0 0 0 0 0 0
-1.3815 1.8546 0.3656 H 0 0 0 0 0 0 0 0 0 0 0 0
-1.1122 0.3289 -2.1752 H 0 0 0 0 0 0 0 0 0 0 0 0
1 2 1 0
2 3 1 0
3 4 2 0
3 5 1 0
2 6 1 0
1 7 1 0
1 8 1 0
1 9 1 0
2 10 1 0
5 11 1 0
6 12 1 0
7 13 1 0
M END
> <CHARGES> (1)
0.079954117054076082,0.17402774992656297,0.33445172084859559,-0.24924322634924762,-0.47926124554573318,-0.37926397069925832,-0.3930474388646486,0.059756578060591724,0.059756578060591724,0.074910619371653109,0.2963731884212602,0.21139157568550943,0.21019375403004686

$$$$
44 changes: 44 additions & 0 deletions testfiles/refmol1.mol
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

RDKit 3D

19 19 0 0 0 0 0 0 0 0999 V2000
-2.4221 -2.3715 -2.2672 C 0 0 0 0 0 0 0 0 0 0 0 0
-2.4433 -2.6197 -0.8925 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7629 -1.7692 -0.0154 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.0616 -0.6544 -0.5079 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.0351 -0.4210 -1.8957 C 0 0 0 0 0 0 0 0 0 0 0 0
-1.7170 -1.2744 -2.7684 C 0 0 0 0 0 0 0 0 0 0 0 0
-0.3019 0.2449 0.4424 C 0 0 0 0 0 0 0 0 0 0 0 0
1.1570 -0.0966 0.4089 C 0 0 0 0 0 0 0 0 0 0 0 0
1.6657 -0.7876 1.3321 O 0 0 0 0 0 0 0 0 0 0 0 0
1.9461 0.3212 -0.6592 O 0 0 0 0 0 0 0 0 0 0 0 0
-0.4675 1.5927 0.0857 O 0 0 0 0 0 0 0 0 0 0 0 0
-2.9484 -3.0317 -2.9445 H 0 0 0 0 0 0 0 0 0 0 0 0
-2.9847 -3.4736 -0.5061 H 0 0 0 0 0 0 0 0 0 0 0 0
-1.7826 -1.9811 1.0464 H 0 0 0 0 0 0 0 0 0 0 0 0
-0.4859 0.4195 -2.3011 H 0 0 0 0 0 0 0 0 0 0 0 0
-1.6959 -1.0869 -3.8342 H 0 0 0 0 0 0 0 0 0 0 0 0
-0.6753 0.0966 1.4839 H 0 0 0 0 0 0 0 0 0 0 0 0
2.9304 0.0858 -0.7021 H 0 0 0 0 0 0 0 0 0 0 0 0
-1.3844 1.8525 0.3644 H 0 0 0 0 0 0 0 0 0 0 0 0
1 2 2 0
2 3 1 0
3 4 2 0
4 5 1 0
5 6 2 0
4 7 1 0
7 8 1 0
8 9 2 0
8 10 1 0
7 11 1 0
6 1 1 0
1 12 1 0
2 13 1 0
3 14 1 0
5 15 1 0
6 16 1 0
7 17 1 0
10 18 1 0
11 19 1 0
M END

Loading