Created
July 11, 2020 18:40
-
-
Save rmatsum836/871c707e55ae985616b026087525fed9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pytest | |
import hypothesis | |
import mbuild as mb | |
from mbuild.formats.xyz import write_xyz | |
from mbuild.utils.io import get_fn | |
from mbuild.tests.base_test import BaseTest | |
from mbuild.exceptions import MBuildError | |
from mbuild.lib.moieties import H2O | |
import hypothesis.strategies as st | |
from hypothesis.strategies import builds, integers, lists, floats, tuples | |
from hypothesis import given, settings | |
def water_box(n_mols=10, box=[3,3,3]): | |
""" Simple function to initalize a box of water """ | |
box = mb.fill_box(H2O(), n_compounds=n_mols, box=box) | |
return box | |
# Set types of input parameters for `water_box` | |
valid_float = floats(min_value=1.1, max_value=3.5) | |
valid_int = integers(min_value=1, max_value=10) | |
valid_tuple = tuples(valid_float, valid_float, valid_float) | |
st_box = st.builds( | |
water_box, | |
valid_int, | |
valid_tuple | |
) | |
@given(nmol=integers(min_value=1, max_value=10), | |
) | |
@settings(deadline=None) | |
def test_water_nmols(nmol): | |
""" Simple example just to understand the API of hypothesis""" | |
water_box(n_mols=nmol) | |
@given(box=valid_tuple | |
) | |
@settings(deadline=None) | |
def test_water_box(box): | |
""" Simple example to understand API of hypothesis """ | |
water_box(box=box) | |
@given(st_box | |
) | |
@settings(deadline=None) | |
def test_water_build(st_box): | |
""" Test to write out an xyz file, read one back in as a Compound and compare """ | |
st_box.save('init.xyz', overwrite=True) | |
read = mb.load('init.xyz') | |
assert (st_box.xyz == read.xyz).all() | |
@given(st_box | |
) | |
@settings(deadline=None) | |
def test_water_io(st_box): | |
""" Test to write out an xyz file, read one back in as a Compound and compare """ | |
st_box.save('init.xyz', overwrite=True) | |
read = mb.load('init.xyz') | |
read.save('init.mol2', overwrite=True) | |
read_2 = mb.load('init.mol2') | |
assert (st_box.xyz == read_2.xyz).all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment