Skip to content

Commit

Permalink
Ci fix (#75)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
selimsami authored Sep 9, 2024
1 parent 0fd2f56 commit 2ed358b
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 56 deletions.
1 change: 0 additions & 1 deletion .github/test_env.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ dependencies:

- setuptools
- xtb
- parmed
- scipy
- numpy
- ase
Expand Down
16 changes: 5 additions & 11 deletions .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: CI

on:
# run once a day at noon UTC
schedule:
- cron: "0 12 * * *"
push:
Expand All @@ -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
Expand All @@ -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 }}
2 changes: 2 additions & 0 deletions qforce/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions qforce/qm/qm_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions qforce/tests/test_fragments.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest

import os
#
from qforce_examples import Gaussian_default
from qforce.main import run_qforce

Expand All @@ -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
Expand All @@ -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
66 changes: 29 additions & 37 deletions qforce/tests/test_run_xtb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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

0 comments on commit 2ed358b

Please sign in to comment.