Skip to content

Commit

Permalink
Fix stochastic test failures
Browse files Browse the repository at this point in the history
  • Loading branch information
avirshup committed Sep 7, 2017
1 parent af755ce commit 32ca9d7
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
22 changes: 19 additions & 3 deletions moldesign/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
'end if')
CONFIG_PATH = os.path.join(CONFIG_DIR, 'moldesign.yml')

NO_NBMOLVIZ_ERR = 10
JUPYTER_ERR = 128
NO_EXAMPLE_OVERWRITE_ERR = 200
OUTDATED_EXAMPLES_ERR = 201


def main():
print('Molecular Design Toolkit v%s Launcher' % MDTVERSION)
Expand Down Expand Up @@ -96,11 +101,13 @@ def main():
CONFIG_PATH = args.config_file

if args.command == 'intro':
nbmolviz_check()
copy_example_dir(use_existing=True)
launch(cwd=EXAMPLE_DIR_TARGET,
path='notebooks/Getting%20Started.ipynb')

elif args.command == 'launch':
nbmolviz_check()
launch()

elif args.command == 'copyexamples':
Expand All @@ -124,6 +131,15 @@ def main():
raise ValueError("Unhandled CLI command '%s'" % args.command)


def nbmolviz_check():
# Checks for the existence of nbmolviz before attempting to launch a notebook
from . import widgets
if not widgets.nbmolviz_installed:
print('ERROR: nbmolviz not found - notebooks not available. Install it by running\n'
' $ pip install nbmolviz`')
sys.exit(NO_NBMOLVIZ_ERR)


def launch(cwd=None, path=''):
server, portnum = launch_jupyter_server(cwd=cwd)
wait_net_service('localhost', portnum, server)
Expand Down Expand Up @@ -154,7 +170,7 @@ def check_existing_examples(use_existing):
'%s, but you are using version %s'%(version, MDTVERSION))
print('To update your examples, please rename or remove "%s"'
% EXAMPLE_DIR_TARGET)
sys.exit(201)
sys.exit(OUTDATED_EXAMPLES_ERR)

if use_existing:
return
Expand All @@ -164,7 +180,7 @@ def check_existing_examples(use_existing):
' 1) Rename or remove the existing directory at %s,'%EXAMPLE_DIR_TARGET,
' 2) Run this command in a different location, or'
' 3) Run `python -m moldesign intro` to launch the example gallery.']))
sys.exit(200)
sys.exit(NO_EXAMPLE_OVERWRITE_ERR)


def launch_jupyter_server(cwd=None): # pragma: no cover
Expand Down Expand Up @@ -238,7 +254,7 @@ def wait_net_service(server, port, process, timeout=None): # pragma: no cover
while True:
if process.poll() is not None:
print('ERROR: Jupyter process exited prematurely')
sys.exit(128)
sys.exit(JUPYTER_ERR)

s = socket.socket()
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
Expand Down
2 changes: 1 addition & 1 deletion moldesign/_tests/test_wfn.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_basis_function_3d_grids_same_in_pyscf_and_mdt(molkey, request):
pyscf_vals = basis_values(mol, mol.wfn.aobasis, randocoords)
with np.errstate(under='ignore'):
mdt_vals = mol.wfn.aobasis(randocoords)
helpers.assert_almost_equal(mdt_vals, pyscf_vals, decimal=6)
helpers.assert_almost_equal(mdt_vals, pyscf_vals, decimal=5)


@pytest.mark.parametrize('molkey', ['h2_rhf_augccpvdz', 'h2_rhf_sto3g'])
Expand Down
3 changes: 2 additions & 1 deletion moldesign/fileio.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def read(f, format=None):
if filename is not None and mol.name not in (None, 'untitled'):
mol.name = filename

mdt.helpers.atom_name_check(mol)
if isinstance(mol, mdt.Molecule):
mdt.helpers.atom_name_check(mol)
return mol


Expand Down

0 comments on commit 32ca9d7

Please sign in to comment.