Numpy 2 Support (#7531)

* facilitate numpy 2.0 support

* so that all tests run smoothly

* not yet ready for this

* w/ casting to bool

* remove formatting changes from this PR
This commit is contained in:
Anna Brünisholz
2024-06-19 07:54:50 +02:00
committed by GitHub
parent d6171aaade
commit 3a8199e4ca
5 changed files with 30 additions and 27 deletions

View File

@@ -27,7 +27,7 @@ def generateAll():
r = get3D(m, True)
print(r)
end = time.time()
print end - start
print(end - start)
def simple_case():
@@ -35,9 +35,9 @@ def simple_case():
smi = 'CCC(C)COCCCC'
m = Chem.MolFromSmiles(smi)
T = get3D(m, False)
print T
print(T)
end = time.time()
print end - start
print(end - start)
if (__name__ == '__main__'):
@@ -49,6 +49,6 @@ if (__name__ == '__main__'):
smi = 'CCC(C)COCCCC'
m = Chem.MolFromSmiles(smi)
T = get3D(m, False)
print T
print(T)
end = time.time()
print end - start
print(end - start)

View File

@@ -5,8 +5,8 @@ from rdkit.Chem import AllChem
from rdkit.Chem import rdMolDescriptors as rdMD
from rdkit.Chem.EState import AtomTypes, EStateIndices
print rdBase.rdkitVersion
print rdBase.boostVersion
print(rdBase.rdkitVersion)
print(rdBase.boostVersion)
def getEState(mol):
@@ -27,7 +27,7 @@ def make3D(mol, steps=50):
if success == -1: # Failed
success = AllChem.EmbedMolecule(mol, useRandomCoords=True)
if success == -1:
raise Error, "Embedding failed!"
raise (Error, "Embedding failed!")
mol = localopt(mol, steps)
return mol
@@ -56,7 +56,7 @@ def generateALL():
thefile.write("\n")
end = time.time()
print end - start
print(end - start)
thefile = open('testSMWHIM.txt', 'w')
@@ -72,14 +72,14 @@ for smi in A:
m = Chem.MolFromSmiles(smi)
m = localopt(m, 100)
#r=get3D(m,True)
print smi
print "---------"
print(smi)
print("---------")
r = rdMD.CalcWHIM(m)
print "Ei:" + str(r[0]) + "," + str(r[1]) + "," + str(r[2]) + "\n"
print "Gi:" + str(r[5]) + "," + str(r[6]) + "," + str(r[7]) + "\n"
print "SI:" + str(rdMD.CalcSpherocityIndex(m))
print "AS:" + str(rdMD.CalcAsphericity(m))
print "EX:" + str(rdMD.CalcEccentricity(m))
print("Ei:" + str(r[0]) + "," + str(r[1]) + "," + str(r[2]) + "\n")
print("Gi:" + str(r[5]) + "," + str(r[6]) + "," + str(r[7]) + "\n")
print("SI:" + str(rdMD.CalcSpherocityIndex(m)))
print("AS:" + str(rdMD.CalcAsphericity(m)))
print("EX:" + str(rdMD.CalcEccentricity(m)))
for item in r:
thefile.write("%.3f," % item)
thefile.write("\n")
@@ -110,4 +110,4 @@ for smi in B:
#writer.write(m)
A = "G1w,G2w,G3w,Gw"
print dir(rdMD)
print(dir(rdMD))

View File

@@ -14,6 +14,7 @@
#include <boost/python.hpp>
#include <RDBoost/boost_numpy.h>
#include <numpy/npy_common.h>
#include <numpy/ndarrayobject.h>
#include <RDBoost/import_array.h>
#include <GraphMol/RDKitBase.h>
#include <GraphMol/Fingerprints/FingerprintGenerator.h>

View File

@@ -48,7 +48,9 @@ def assignFilters(data, nameSmilesColumn='smiles'):
sma = Chem.MolFromSmarts(NO_filter, mergeHs=True)
for smi in data[nameSmilesColumn]:
qc, NO_filter, fracNO, co, sc, sm = [np.NaN] * 6
qc, NO_filter, fracNO, co, sc, sm = [np.nan] * 6
# The following files require numpy and were explicitely checked for their compatibility.
try:
mol = Chem.MolFromSmiles(smi)

View File

@@ -507,9 +507,9 @@ def OptimizeMol(mol, bm, atomMatches=None, excludedVolumes=None, forceConstant=1
>>> p0 = conf.GetAtomPosition(0)
>>> p3 = conf.GetAtomPosition(3)
>>> d03 = p0.Distance(p3)
>>> d03 >= pcophore.getLowerBound(0,1) - 0.01
>>> bool(d03 >= pcophore.getLowerBound(0,1) - 0.01)
True
>>> d03 <= pcophore.getUpperBound(0,1) + 0.01
>>> bool(d03 <= pcophore.getUpperBound(0,1) + 0.01)
True
If we optimize without the distance constraints (provided via the atomMatches
@@ -525,9 +525,9 @@ def OptimizeMol(mol, bm, atomMatches=None, excludedVolumes=None, forceConstant=1
>>> p0 = conf.GetAtomPosition(0)
>>> p3 = conf.GetAtomPosition(3)
>>> d03 = p0.Distance(p3)
>>> d03 >= pcophore.getLowerBound(0, 1) - 0.01
>>> bool(d03 >= pcophore.getLowerBound(0, 1) - 0.01)
True
>>> d03 <= pcophore.getUpperBound(0, 1) + 0.01
>>> bool(d03 <= pcophore.getUpperBound(0, 1) + 0.01)
False
"""
@@ -862,7 +862,7 @@ def CombiEnum(sequence):
def DownsampleBoundsMatrix(bm, indices, maxThresh=4.0):
""" Removes rows from a bounds matrix that are that are greater
""" Removes rows from a bounds matrix that are that are greater
than a threshold value away from a set of other points
Returns the modfied bounds matrix
@@ -992,10 +992,10 @@ def CoarseScreenPharmacophore(atomMatch, bounds, pcophore, verbose=False):
>>> pcophore.setUpperBound(1,3, 1.9)
>>> pcophore.setLowerBound(2,3, 1.1)
>>> pcophore.setUpperBound(2,3, 1.9)
>>> bounds = numpy.array([[0, 3, 3, 3],
... [2, 0, 2, 2],
... [2, 1, 0, 2],
... [2, 1, 1, 0]],
>>> bounds = numpy.array([[0, 3, 3, 3],
... [2, 0, 2, 2],
... [2, 1, 0, 2],
... [2, 1, 1, 0]],
... dtype=numpy.float64)
>>> CoarseScreenPharmacophore(((0, ), (1, ), (2, ), (3, )), bounds, pcophore)