From 2ed358b63d0b6550bbda05118f26f9571d1a6eff Mon Sep 17 00:00:00 2001 From: Selim Sami Date: Mon, 9 Sep 2024 11:28:55 -0700 Subject: [PATCH] Ci fix (#75) * ci fix * ci fix * ci fix * ci fix * ci fix * ci fix * ci fix * ci fix * ci fix * ci fix * ci fix * ci fix * ci fix --- .github/test_env.yaml | 1 - .github/workflows/CI.yaml | 16 +++------ qforce/main.py | 2 ++ qforce/qm/qm_base.py | 4 +-- qforce/tests/test_fragments.py | 12 ++++--- qforce/tests/test_run_xtb.py | 66 +++++++++++++++------------------- 6 files changed, 45 insertions(+), 56 deletions(-) diff --git a/.github/test_env.yaml b/.github/test_env.yaml index cea407c..bad77c8 100644 --- a/.github/test_env.yaml +++ b/.github/test_env.yaml @@ -8,7 +8,6 @@ dependencies: - setuptools - xtb - - parmed - scipy - numpy - ase diff --git a/.github/workflows/CI.yaml b/.github/workflows/CI.yaml index b29970a..68a0f86 100644 --- a/.github/workflows/CI.yaml +++ b/.github/workflows/CI.yaml @@ -1,7 +1,6 @@ name: CI on: - # run once a day at noon UTC schedule: - cron: "0 12 * * *" push: @@ -19,8 +18,6 @@ jobs: steps: - uses: actions/checkout@v2 - - # More info on options: https://github.com/conda-incubator/setup-miniconda - uses: mamba-org/setup-micromamba@main with: environment-file: .github/test_env.yaml @@ -30,22 +27,19 @@ jobs: pytest=${{ matrix.pytest }} - name: Install package - - # conda setup requires this special shell shell: bash -l {0} run: | python -m pip install . --no-deps - conda list - - name: Run tests - # conda setup requires this special shell + - name: Run tests shell: bash -l {0} - run: | - pytest -v -m "not slow" --cov=qforce --cov-report=xml --color=yes qforce/tests/ + pytest -v --cov=qforce --cov-report=xml --color=yes qforce/tests/ + - name: CodeCov - uses: codecov/codecov-action@v1 + uses: codecov/codecov-action@v3 with: + token: ${{ secrets.CODECOV_TOKEN }} file: ./coverage.xml flags: unittests name: codecov-${{ matrix.os }}-py${{ matrix.python-version }} diff --git a/qforce/main.py b/qforce/main.py index 90d163b..68db29e 100755 --- a/qforce/main.py +++ b/qforce/main.py @@ -60,6 +60,8 @@ def run_qforce(input_arg, ext_q=None, ext_lj=None, config=None, presets=None): print_outcome(job.dir) + return mol + def run_hessian_fitting_for_external(job_dir, qm_data, ext_q=None, ext_lj=None, config=None, presets=None): diff --git a/qforce/qm/qm_base.py b/qforce/qm/qm_base.py index 2bd6b81..c172f11 100755 --- a/qforce/qm/qm_base.py +++ b/qforce/qm/qm_base.py @@ -54,8 +54,8 @@ def _read_fchk_file(fchk_file): line = file.readline() hessian.extend(line.split()) - coords = np.asfarray(coords, float) - hessian = np.asfarray(hessian, float) + coords = np.asarray(coords, dtype=float) + hessian = np.asarray(hessian, dtype=float) coords = np.reshape(coords, (-1, 3)) elements = np.array(elements) coords = coords * Bohr diff --git a/qforce/tests/test_fragments.py b/qforce/tests/test_fragments.py index e375d1a..d2fccd6 100644 --- a/qforce/tests/test_fragments.py +++ b/qforce/tests/test_fragments.py @@ -1,5 +1,6 @@ import pytest - +import os +# from qforce_examples import Gaussian_default from qforce.main import run_qforce @@ -26,8 +27,10 @@ def test_BatchRun(batch_run, exist, tmpdir): except SystemExit: pass # Fragment file generated - assert tmpdir.join('propane_qforce').join('fragments').join( - 'CC_H8C3_d91b46644317dee9c2b868166c66a18c~1.inp').isfile() + + inp = [file for file in os.listdir(tmpdir.join('propane_qforce').join('fragments')) if file.endswith('.inp')][0] + + assert tmpdir.join('propane_qforce').join('fragments').join(inp).isfile() tmpdir.join('propane_qforce').join('fragments').remove() # Second run @@ -38,5 +41,4 @@ def test_BatchRun(batch_run, exist, tmpdir): pass # Fragment file generated again if batch_run is False # Fragment file not generated again if batch_run is True - assert tmpdir.join('propane_qforce').join('fragments').join( - 'CC_H8C3_d91b46644317dee9c2b868166c66a18c~1.inp').isfile() is exist + assert tmpdir.join('propane_qforce').join('fragments').join(inp).isfile() is exist diff --git a/qforce/tests/test_run_xtb.py b/qforce/tests/test_run_xtb.py index aa68a35..0ef226f 100644 --- a/qforce/tests/test_run_xtb.py +++ b/qforce/tests/test_run_xtb.py @@ -2,7 +2,6 @@ import numpy as np import pytest -import parmed as pmd from subprocess import call from qforce.main import run_qforce from qforce_examples import xTB_default @@ -46,29 +45,29 @@ def propane(tmp_path_factory): except SystemExit: pass + frag_dir = outdir / 'propane_qforce' / 'fragments' + inp = [file for file in os.listdir(frag_dir) if file.endswith('.inp')][0] os.chdir('fragments') - run_fragment = outdir / 'propane_qforce' / 'fragments' / 'CC_H8C3_d91b46644317dee9c2b868166c66a18c~1.inp' + run_fragment = frag_dir / inp + call(run_fragment.read_text(), shell=True) # Generate the topology try: - run_qforce(input_arg=str(xyz), + mol = run_qforce(input_arg=str(xyz), config=str(setting)) except SystemExit: pass - top = pmd.load_file(str(outdir / 'propane_qforce' / 'gas.top'), - xyz = str(outdir / 'propane_qforce' / 'gas.gro')) os.chdir(cwd) - return top + return mol - def test_top(self, propane): - '''Test if the whole process runs.''' - assert isinstance(propane, pmd.gromacs.GromacsTopologyFile) + # def test_top(self, propane): + # '''Test if the whole process runs.''' + # assert isinstance(propane, pmd.gromacs.GromacsTopologyFile) def test_charge(self, propane): '''Test if the charges are generated in the same fashion.''' - charges = [atom.charge for atom in propane.atoms] ref_charge = [-0.10206769, -0.04738168, 0.03075230, @@ -81,40 +80,33 @@ def test_charge(self, propane): 0.03359926, 0.03359765, ] - assert np.allclose(ref_charge, charges, atol=0.01) + assert np.allclose(ref_charge, propane.non_bonded.q, atol=0.01) def test_elements(self, propane): - atom_ids = [atom.atomic_number for atom in propane.atoms] - assert [6, 6, 1, 1, 1, 6, 1, 1, 1, 1, 1] == atom_ids + assert [6, 6, 1, 1, 1, 6, 1, 1, 1, 1, 1] == list(propane.elements) def test_angles(self, propane): - assert len(propane.angles) == 18 - assert propane.angles[0].funct == 5 - assert propane.angles[0].atom1.idx == 0 - assert propane.angles[0].atom2.idx == 1 - assert propane.angles[0].atom3.idx == 5 - assert np.isclose(propane.angles[0].type.k, 54.72, atol=0.01) - assert np.isclose(propane.angles[0].type.theteq, 111.62, atol=0.01) + angles = list(propane.terms['angle']) + assert len(angles) == 18 + assert list(angles[0].atomids) == [0, 1, 5] + assert np.isclose(angles[0].fconst, 457.945, atol=0.01) + assert np.isclose(np.degrees(angles[0].equ), 111.62, atol=0.01) def test_bonds(self, propane): - assert len(propane.bonds) == 10 - assert propane.bonds[0].funct == 1 - assert propane.bonds[0].atom1.idx == 0 - assert propane.bonds[0].atom2.idx == 1 - assert np.isclose(propane.bonds[0].type.k, 211.478, atol=0.01) - assert np.isclose(propane.bonds[0].type.req, 1.5242, atol=0.01) + bonds = list(propane.terms['bond']) + assert len(bonds) == 10 + assert list(bonds[0].atomids) == [0, 1] + assert np.isclose(bonds[0].fconst, 1769.660, atol=0.01) + assert np.isclose(bonds[0].equ, 1.5242, atol=0.01) def test_dihedrals(self, propane): - assert len(propane.rb_torsions) == 2 - assert propane.rb_torsions[0].atom1.idx == 2 - assert propane.rb_torsions[0].atom2.idx == 0 - assert propane.rb_torsions[0].atom3.idx == 1 - assert propane.rb_torsions[0].atom4.idx == 5 - assert propane.rb_torsions[0].funct == 3 - assert np.isclose(propane.rb_torsions[0].type.c0, 0.9964, atol=0.01) + diheds = list(propane.terms['dihedral/flexible']) + assert len(diheds) == 2 + assert list(diheds[0].atomids) == [2, 0, 1, 5] + assert np.isclose(diheds[0].equ[0], 4.169, atol=0.01) def test_defaults(self, propane): - assert propane.defaults.comb_rule == 3 - assert propane.defaults.fudgeLJ == 0.5 - assert propane.defaults.fudgeQQ == 0.5 - assert propane.defaults.nbfunc == 1 + assert propane.non_bonded.comb_rule == 3 + assert propane.non_bonded.fudge_lj == 0.5 + assert propane.non_bonded.fudge_q == 0.5 +