Skip to content

Commit f636f8d

Browse files
tests for csearch and cmin
1 parent 869089d commit f636f8d

File tree

3 files changed

+427
-1
lines changed

3 files changed

+427
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
Example_workflows_BEGINNING/
2-
tests/
32
# Byte-compiled / optimized / DLL files
43
__pycache__/
54
*.py[cod]

tests/test_cmin.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/usr/bin/env python
2+
3+
######################################################.
4+
# Testing with pytest: #
5+
# CMIN module #
6+
######################################################.
7+
8+
import os
9+
import pytest
10+
import subprocess
11+
from aqme.cmin import cmin
12+
import glob
13+
from pathlib import Path
14+
import rdkit
15+
16+
# saves the working directory
17+
w_dir_main = os.getcwd()
18+
cmin_methods_dir = w_dir_main + "/tests/cmin_methods"
19+
cmin_xtb_dir = w_dir_main + "/tests/cmin_xtb"
20+
21+
# tests for parameters of csearch random initialzation
22+
@pytest.mark.parametrize(
23+
"program, sdf, ani_method, xtb_method, opt_steps, opt_fmax, output_nummols",
24+
[
25+
# tests for conformer generation with RDKit
26+
("ani", "pentane_rdkit_methods.sdf",'ANI1ccx', None, 100, 0.08, 4),
27+
("xtb", "pentane_rdkit_methods.sdf",None, 'GFN2-xTB', 400, 0.03, 4),
28+
],
29+
)
30+
def test_cmin_methods(program, sdf, ani_method, xtb_method, opt_steps, opt_fmax, output_nummols ):
31+
os.chdir(cmin_methods_dir)
32+
# runs the program with the different tests
33+
if program =='ani':
34+
cmin(w_dir_main=cmin_methods_dir,ani_method=ani_method, program=program, files=sdf, opt_steps=opt_steps, opt_fmax=opt_fmax)
35+
elif program =='xtb':
36+
cmin(w_dir_main=cmin_methods_dir,xtb_method=xtb_method, program=program, files=sdf, opt_steps=opt_steps, opt_fmax=opt_fmax)
37+
38+
#tests here
39+
file = str("CMIN/" + program + "/" + sdf.split('.')[0] + "_" + program + ".sdf")
40+
file2 = str("CMIN/" + program + "/" + sdf.split('.')[0] + "_" + program + "_all_confs.sdf")
41+
assert os.path.exists(file)
42+
assert os.path.exists(file2)
43+
44+
mols = rdkit.Chem.SDMolSupplier(file,removeHs=False)
45+
assert len(mols) == output_nummols
46+
os.chdir(w_dir_main)
47+
48+
# tests for parameters of cmin paramters
49+
@pytest.mark.parametrize(
50+
"program, sdf, metal_complex,metal,metal_oxi,complex_type, charge, mult, xtb_solvent, ewin_cmin, initial_energy_threshold, energy_threshold,rms_threshold,xtb_accuracy,xtb_electronic_temperature, xtb_max_iterations, output_nummols",
51+
[
52+
# tests for conformer generation with RDKit
53+
("xtb", "pentane_rdkit.sdf",False,None,None,None, 0, 1, 'Chloroform', 5,0.003, 0.4,0.5,0.01,298,500,4 ),
54+
("xtb", "Pd_complex_0_rdkit.sdf",True,['Pd'],[2],'squareplanar',0,1,"none",8,0.004,0.3,0.2,0.02,300,400, 2),
55+
],
56+
)
57+
def test_cmin_xtb_parameters(program, sdf, metal_complex,metal,metal_oxi,complex_type,charge, mult, xtb_solvent, ewin_cmin, initial_energy_threshold, energy_threshold,rms_threshold,xtb_accuracy,xtb_electronic_temperature, xtb_max_iterations, output_nummols ):
58+
os.chdir(cmin_xtb_dir)
59+
# runs the program with the different tests
60+
if not metal_complex:
61+
cmin(w_dir_main=cmin_xtb_dir, program=program, files=sdf,
62+
charge=charge, mult=mult, xtb_solvent=xtb_solvent, ewin_cmin=ewin_cmin, initial_energy_threshold=initial_energy_threshold,
63+
energy_threshold=energy_threshold,rms_threshold=rms_threshold,
64+
xtb_accuracy=xtb_accuracy,xtb_electronic_temperature=xtb_electronic_temperature, xtb_max_iterations=xtb_max_iterations)
65+
else:
66+
cmin(w_dir_main=cmin_xtb_dir, program=program, files=sdf, metal_complex=metal_complex,metal=metal,metal_oxi=metal_oxi,complex_type=complex_type,
67+
charge=charge, mult=mult, xtb_solvent=xtb_solvent, ewin_cmin=ewin_cmin, initial_energy_threshold=initial_energy_threshold,
68+
energy_threshold=energy_threshold,rms_threshold=rms_threshold,
69+
xtb_accuracy=xtb_accuracy,xtb_electronic_temperature=xtb_electronic_temperature, xtb_max_iterations=xtb_max_iterations)
70+
71+
#tests here
72+
file = str("CMIN/" + program + "/" + sdf.split('.')[0] + "_" + program + ".sdf")
73+
file2 = str("CMIN/" + program + "/" + sdf.split('.')[0] + "_" + program + "_all_confs.sdf")
74+
assert os.path.exists(file)
75+
assert os.path.exists(file2)
76+
77+
mols = rdkit.Chem.SDMolSupplier(file,removeHs=False)
78+
assert len(mols) == output_nummols
79+
80+
assert int(mols[0].GetProp('Real charge')) == charge
81+
assert int(mols[0].GetProp('Mult')) == mult
82+
83+
os.chdir(w_dir_main)

0 commit comments

Comments
 (0)