Skip to content

Commit

Permalink
move to pytest
Browse files Browse the repository at this point in the history
 * move to pytest for testing
 * add automatic deploy configuration to travis.yml
 * update README
  • Loading branch information
ltalirz committed Apr 2, 2019
1 parent 2b148af commit b50fcb4
Show file tree
Hide file tree
Showing 9 changed files with 244 additions and 252 deletions.
27 changes: 26 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ env:
- PLUGIN_DIR: aiida-diff
- TEST_AIIDA_BACKEND: django
- AIIDA_VERSION: develop
- AIIDA_DEVELOP_GIT_HASH: 0ca5d991d039dca2261df3d6ad8da2f03d591caa
- AIIDA_DEVELOP_GIT_HASH: e852d66fc51345fbdb8ebf98580a5646d79bc043
# add network executable to PATH
#- PATH=${PATH}:${TRAVIS_BUILD_DIR}
# use 'network' script from .travis-data
Expand All @@ -63,3 +63,28 @@ script:

after_success:
- coveralls

jobs:
include:
- stage: deploy
# Make sure the tag is valid semver
if: "branch = master AND tag =~ ^v[0-9]+\\.[0-9]+\\.[0-9]+(a|b|rc)?[0-9]*$"
addons: skip
python: 3.6
before_install: skip
install: skip
before_script: skip
script: skip
env: ignore
after_deploy:
- echo "Deployed $TRAVIS_TAG to PyPI"
deploy: &pypi
provider: pypi
skip_existing: true
username: aiida-bot
password:
# See https://docs.travis-ci.com/user/encryption-keys/ for instructions
secure: "2CXKbNjVneb/Xmh9xjNA60GcmN4+tkLQR6PbS3eUz7WuSRKxpi406cTfaYHAv1TJKIDEPNDElLXktrHIBuZcj/V+4DgVQN3uS19NeXLDFMwuf1CKv46yQTO0iTGfo3FUPbCvvC4P3fp6geKSn6TUtUJaZmRbYIqgxJLC+qxewctR8Y/EyTW7SiKhJFfgTGfIQ1diDNfrCG7cPI2RnuTBo8oA3HW3BkyCJiMQ6Nyeodb7k2foLcdFOJuoSXKZiaoGCdaMyHyL32ZOp6IKU2t5RF+q7fT1trtlnWFhhDf766I/+AwH0h+/GZYGP5IZjARhqU290COIDhv4VI66D7EN82tBDKQFrm7PqxC+1no4FrjHQmF6hN31ATphdHqkygh0jg4W+AP8+WJUKwp3/mAnS4q1i7dUbiQtMKNl2+6dm0HSUCVsLHFLVdvKsfXYppNT7qNhWavOJdUfcC7veZHRiuOCYfFXqz1h2NuJ1OwnZ6GKyw0fpsw7Zpmtt4qJ+IIUGOsnreKB6NW311DcL3Gx4hWcLdIlXfP9QbVttztlsQnSVR0UAhA0UoCzzcZmdgZYRArHb7I75BInoEK5seKvOImCVHxfFKH9AN8gkZPOgauFCC3KzbzG01ofVSMhDgo88qfV9p8LFPKzmw9MQuYIU7YOQWQ8iSxzWYKDg7QIR4c="
on:
repo: ltalirz/aiida-zeopp
tags: true
21 changes: 9 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ AiiDA plugin for [Zeo++](http://www.zeoplusplus.org/)
## Installation

```shell
git clone https://github.com/ltalirz/aiida-zeopp aiida-zeopp
cd aiida-zeopp
pip install -e . # also installs aiida, if missing (but not postgres)
pip install aiida-zeopp
reentry scan
verdi quicksetup # better to set up a new profile
verdi calculation plugins # should now show your calclulation plugins
Expand All @@ -29,7 +27,7 @@ verdi calculation plugins # should now show your calclulation plugins
```python
d = { 'sa': [1.82, 1.82, 1000], 'volpo': [1.82, 1.82, 1000], 'chan': 1.2 }
NetworkParameters = DataFactory('zeopp.parameters')
calc.use_parameters(NetworkParameters(dict=d))
inputs['parameters'] = NetworkParameters(dict=d)
```
* `NetworkParameters` validates the command line options using [voluptuous](https://github.com/alecthomas/voluptuous).
Find out about supported options:
Expand All @@ -40,7 +38,7 @@ verdi calculation plugins # should now show your calclulation plugins
* Add alternative atomic radii file
```python
SinglefileData = DataFactory('singlefile')
calc.use_atomic_radii(SinglefileData(file='/path/to/file'))
inputs['atomic_radii'] = SinglefileData(file='/path/to/file')
```

## Examples
Expand All @@ -50,8 +48,7 @@ See `examples` folder for complete examples of setting up a calculation or workf
```shell
verdi daemon start # make sure the daemon is running
cd examples
verdi run submit.py # submit test calculation
verdi calculation list -a # check status of calculation
verdi run submit.py # runs test calculation
```

## Tests
Expand All @@ -61,13 +58,13 @@ verdi calculation list -a # check status of calculation
The following will discover and run all unit tests:
```shell
pip install -e .[testing]
python manage.py
pytest
```

## Analyzing output

```shell
$ verdi calculation show 88
$ verdi process show 88
----------- ------------------------------------------------------------------------------
type NetworkCalculation
pk 88
Expand All @@ -92,7 +89,7 @@ retrieved 90 FolderData
structure_cssr 91 SinglefileData
output_parameters 92 ParameterData

$ verdi calculation res 88
$ verdi calcjob res 88
{
"ASA_A^2": 3532.09,
"ASA_m^2/cm^3": 1932.13,
Expand Down Expand Up @@ -141,15 +138,15 @@ $ verdi calculation res 88
"Unitcell_volume": 18280.8
}

$ verdi calculation outputls 88
$ verdi calcjob outputls 88
_scheduler-stderr.txt
_scheduler-stdout.txt
out.chan
out.cssr
out.sa
out.volpo

$ verdi calculation outputcat 88 -p out.sa
$ verdi calcjob outputcat 88 -p out.sa
@ out.sa Unitcell_volume: 18280.8 Density: 0.879097 ASA_A^2: 3532.09 ASA_m^2/cm^3: 1932.13 ASA_m^2/g: 2197.86 NASA_A^2: 0 NASA_m^2/cm^3: 0 NASA_m^2/g: 0
Number_of_channels: 1 Channel_surface_area_A^2: 3532.09
Number_of_pockets: 0 Pocket_surface_area_A^2:
Expand Down
3 changes: 3 additions & 0 deletions aiida_zeopp/calculations/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from aiida.engine import CalcJob
from aiida.common import (CalcInfo, CodeInfo)
from aiida.plugins import DataFactory
from aiida.orm import Data
import six

NetworkParameters = DataFactory('zeopp.parameters')
Expand Down Expand Up @@ -51,6 +52,8 @@ def define(cls, spec):
'Empty block file. This indicates the calculation of blocked pockets did not finish.'
)

spec.outputs.dynamic = True
spec.outputs.valid_type = Data
spec.output(
'output_parameters',
valid_type=Dict,
Expand Down
194 changes: 85 additions & 109 deletions aiida_zeopp/calculations/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,112 +4,88 @@
from __future__ import absolute_import
import os
import io

import aiida_zeopp.tests as zt


class TestNetwork(zt.PluginTestCase):
def setUp(self):
self.code = zt.get_code(entry_point='zeopp.network')

def test_submit_HKUST1(self):
"""Test submitting a calculation"""
from aiida_zeopp.tests import TEST_DIR
from aiida_zeopp.calculations.network import NetworkCalculation
from aiida.engine import run_get_node

# Prepare input parameters
from aiida.plugins import DataFactory
NetworkParameters = DataFactory('zeopp.parameters')
parameters = NetworkParameters(dict={'cssr': True})

CifData = DataFactory('cif')
structure = CifData(
file=os.path.join(TEST_DIR, 'HKUST-1.cif'), parse_policy='lazy')

# set up calculation
options = {
"resources": {
"num_machines": 1,
"num_mpiprocs_per_machine": 1,
},
"max_wallclock_seconds": 3 * 60,
}

inputs = {
'code': self.code,
'parameters': parameters,
'structure': structure,
'metadata': {
'options': options,
'label': "aiida_zeopp format conversion",
'description': "Test converting .cif to .cssr format",
},
}

_result, node = run_get_node(NetworkCalculation, **inputs)

cssr = io.open(
os.path.join(TEST_DIR, 'HKUST-1.cssr'), 'r',
encoding='utf8').read()
self.assertEqual(cssr, node.outputs.structure_cssr.get_content())

def test_submit_MgO(self):
"""Test submitting a calculation
This includes a radii file.
"""
from aiida_zeopp.tests import TEST_DIR
from aiida_zeopp.calculations.network import NetworkCalculation
from aiida.engine import run_get_node
from aiida.plugins import DataFactory

# Prepare input parameters
parameters = DataFactory('zeopp.parameters')(
dict={
'cssr': True,
'res': True,
'sa': [1.82, 1.82, 5000],
'vsa': [1.82, 1.82, 5000],
'volpo': [1.82, 1.82, 5000],
'chan': 1.2,
'ha': False,
'strinfo': True,
# 'gridG': True,
})

structure = DataFactory('cif')(
file=os.path.join(TEST_DIR, 'MgO.cif'), parse_policy='lazy')

atomic_radii = DataFactory('singlefile')(
file=os.path.join(TEST_DIR, 'MgO.rad'))

# set up calculation
options = {
"resources": {
"num_machines": 1,
"num_mpiprocs_per_machine": 1,
},
"max_wallclock_seconds": 30,
}

inputs = {
'code': self.code,
'parameters': parameters,
'structure': structure,
'atomic_radii': atomic_radii,
'metadata': {
'options': options,
'label': "aiida_zeopp format conversion",
'description': "Test converting .cif to .cssr format",
},
}

_result, node = run_get_node(NetworkCalculation, **inputs)

self.assertAlmostEqual(
node.outputs.output_parameters.get_attribute('Density'),
3.18223,
places=4)
self.assertEqual(
node.outputs.output_parameters.get_attribute('ASA_m^2/g'), 0.0)
import pytest


def test_submit_HKUST1(clear_database, network_code, basic_options): # pylint: disable=unused-argument
"""Test submitting a calculation"""
from aiida_zeopp.tests import TEST_DIR
from aiida_zeopp.calculations.network import NetworkCalculation
from aiida.engine import run_get_node

# Prepare input parameters
from aiida.plugins import DataFactory
NetworkParameters = DataFactory('zeopp.parameters')
parameters = NetworkParameters(dict={'cssr': True})

CifData = DataFactory('cif')
structure = CifData(
file=os.path.join(TEST_DIR, 'HKUST-1.cif'), parse_policy='lazy')

inputs = {
'code': network_code,
'parameters': parameters,
'structure': structure,
'metadata': {
'options': basic_options,
'label': "aiida_zeopp format conversion",
'description': "Test converting .cif to .cssr format",
},
}

_result, node = run_get_node(NetworkCalculation, **inputs)

cssr = io.open(
os.path.join(TEST_DIR, 'HKUST-1.cssr'), 'r', encoding='utf8').read()
assert (cssr == node.outputs.structure_cssr.get_content())


def test_submit_MgO(clear_database, network_code, basic_options): # pylint: disable=unused-argument
"""Test submitting a calculation
This includes a radii file.
"""
from aiida_zeopp.tests import TEST_DIR
from aiida_zeopp.calculations.network import NetworkCalculation
from aiida.engine import run_get_node
from aiida.plugins import DataFactory

# Prepare input parameters
parameters = DataFactory('zeopp.parameters')(
dict={
'cssr': True,
'res': True,
'sa': [1.82, 1.82, 5000],
'vsa': [1.82, 1.82, 5000],
'volpo': [1.82, 1.82, 5000],
'chan': 1.2,
'ha': False,
'strinfo': True,
# 'gridG': True,
})

structure = DataFactory('cif')(
file=os.path.join(TEST_DIR, 'MgO.cif'), parse_policy='lazy')

atomic_radii = DataFactory('singlefile')(
file=os.path.join(TEST_DIR, 'MgO.rad'))

# set up calculation
inputs = {
'code': network_code,
'parameters': parameters,
'structure': structure,
'atomic_radii': atomic_radii,
'metadata': {
'options': basic_options,
'label': "aiida_zeopp format conversion",
'description': "Test converting .cif to .cssr format",
},
}

_result, node = run_get_node(NetworkCalculation, **inputs)

assert pytest.approx(
node.outputs.output_parameters.get_attribute('Density'),
0.01) == 3.18223
assert node.outputs.output_parameters.get_attribute('ASA_m^2/g') == 0.0

0 comments on commit b50fcb4

Please sign in to comment.