Skip to content

Commit 08d088f

Browse files
authored
Merge pull request #23 from libefp2/pylibefp2
Bringing pylibefp functionality in sync with the master libefp version. Long overdue.
2 parents 1cd8caa + 793d977 commit 08d088f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+9806
-347
lines changed

.gitignore

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
/include/
2525
tags
2626
build*/
27-
/installed/
27+
/install*/
2828
/cmake-build-debug/
29-
compilation.log
30-
29+
comp*.log
30+
/lib
31+
.DS_Store
32+
__pycache__/
33+
*.pyc
34+
*.pyo

cpp.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
rm -rf build
2+
rm -rf installed
3+
4+
cmake -S . -B build \
5+
-D CMAKE_INSTALL_PREFIX=$LIBEFP_DIR/installed \
6+
-D BUILD_SHARED_LIBS=ON \
7+
-D LIBEFP_ENABLE_OPENMP=ON
8+
9+
cmake --build build --target install

efpmd/src/main.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ static void state_init(struct state *state, const struct cfg *cfg, const struct
445445
state->energy = 0;
446446
state->grad = xcalloc(sys->n_frags * 6 + sys->n_charges * 3, sizeof(double));
447447
state->ff = NULL;
448-
state->torch = NULL;
448+
state->torch = NULL;
449449
state->torch_grad = NULL;
450450

451451
if (cfg_get_bool(cfg, "enable_ff")) {
@@ -472,6 +472,7 @@ static void state_init(struct state *state, const struct cfg *cfg, const struct
472472
// initiate torch state
473473
#ifdef TORCH_SWITCH
474474
if (cfg_get_bool(cfg, "enable_torch")) {
475+
check_fail(efp_get_frag_count(state->efp, &nfrag));
475476
if (cfg_get_int(cfg, "special_fragment") < 0 || cfg_get_int(cfg, "special_fragment") > nfrag-1)
476477
error("do not know for which fragment to compute torch: set special_fragment");
477478

lib/pylibefp/__init__.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#
2+
# @BEGIN LICENSE
3+
#
4+
# pylibefp/__init__.py:
5+
#
6+
# Copyright (c) 2017-2019 The Psi4 Developers
7+
#
8+
# All rights reserved. Use of this source code is governed by a
9+
# BSD-style license that can be found in the LICENSE file.
10+
#
11+
# @END LICENSE
12+
#
13+
14+
import os
15+
pylibefp_module_loc = os.path.dirname(os.path.abspath(__file__))
16+
17+
# Init core
18+
from . import core
19+
20+
# Load driver and version paraphernalia
21+
from .wrapper import from_dict, to_dict
22+
from .exceptions import EFPException, Fatal, NoMemory, FileNotFound, EFPSyntaxError, UnknownFragment, PolNotConverged, PyEFPSyntaxError
23+
__version__ = "2.0.0"
24+
25+
# A few extraneous functions
26+
from .extras import test
761 Bytes
Binary file not shown.
3.84 KB
Binary file not shown.
2.04 KB
Binary file not shown.
73.5 KB
Binary file not shown.

lib/pylibefp/exceptions.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#
2+
# @BEGIN LICENSE
3+
#
4+
# pylibefp/wrapper/exceptions.py:
5+
#
6+
# Copyright (c) 2017-2019 The Psi4 Developers
7+
#
8+
# All rights reserved. Use of this source code is governed by a
9+
# BSD-style license that can be found in the LICENSE file.
10+
#
11+
# @END LICENSE
12+
#
13+
"""Module with non-generic exceptions classes."""
14+
from . import extras
15+
16+
17+
class EFPException(Exception):
18+
"""Error class for pylibefp."""
19+
extras._success_flag_ = False
20+
21+
22+
class Fatal(EFPException):
23+
"""Fatal error has occurred."""
24+
def __init__(self, msg):
25+
EFPException.__init__(self, msg)
26+
self.message = r"""\nEFPException: Fatal error has occurred. {}\n\n""".format(repr(msg))
27+
28+
29+
class NoMemory(EFPException):
30+
"""Insufficient memory."""
31+
def __init__(self, msg):
32+
EFPException.__init__(self, msg)
33+
self.message = r"""\nEFPException: Insufficient memory. {}\n\n""".format(repr(msg))
34+
35+
36+
class FileNotFound(EFPException):
37+
"""File not found."""
38+
def __init__(self, msg):
39+
EFPException.__init__(self, msg)
40+
self.message = r"""\nEFPException: File not found. {}\n\n""".format(repr(msg))
41+
42+
43+
class EFPSyntaxError(EFPException):
44+
"""Syntax error."""
45+
def __init__(self, msg):
46+
EFPException.__init__(self, msg)
47+
self.message = r"""\nEFPException: Libefp syntax error. {}\n\n""".format(repr(msg))
48+
49+
50+
class UnknownFragment(EFPException):
51+
"""Unknown EFP fragment."""
52+
def __init__(self, msg):
53+
EFPException.__init__(self, msg)
54+
self.message = r"""\nEFPException: Unknown EFP fragment. {}\n\n""".format(repr(msg))
55+
56+
57+
class PolNotConverged(EFPException):
58+
"""Polarization SCF procedure did not converge."""
59+
def __init__(self, msg):
60+
EFPException.__init__(self, msg)
61+
self.message = r"""\nEFPException: Polarization SCF procedure did not converge. {}\n\n""".format(repr(msg))
62+
63+
64+
class PyEFPSyntaxError(EFPException):
65+
"""Syntax error."""
66+
def __init__(self, msg):
67+
EFPException.__init__(self, msg)
68+
self.message = r"""\nEFPException: Pylibefp syntax error. {}\n\n""".format(repr(msg))

lib/pylibefp/extras.py

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#
2+
# @BEGIN LICENSE
3+
#
4+
# pylibefp/extras.py:
5+
#
6+
# Copyright (c) 2017-2019 The Psi4 Developers
7+
#
8+
# All rights reserved. Use of this source code is governed by a
9+
# BSD-style license that can be found in the LICENSE file.
10+
#
11+
# @END LICENSE
12+
#
13+
14+
import os
15+
16+
_success_flag_ = False
17+
18+
### # Working directory
19+
### _input_dir_ = os.getcwd()
20+
###
21+
### def get_input_directory():
22+
### return _input_dir_
23+
24+
25+
# Testing
26+
def test(extent='full', extras=None):
27+
"""Runs a test suite through pytest.
28+
29+
Parameters
30+
----------
31+
extent : {'smoke', 'quick', 'full', 'long'}
32+
All choices are defined, but choices may be redundant in some projects.
33+
_smoke_ will be minimal "is-working?" test(s).
34+
_quick_ will be as much coverage as can be got quickly, approx. 1/3 tests.
35+
_full_ will be the whole test suite, less some exceedingly long outliers.
36+
_long_ will be the whole test suite.
37+
extras : list
38+
Additional arguments to pass to `pytest`.
39+
40+
Returns
41+
-------
42+
int
43+
Return code from `pytest.main()`. 0 for pass, 1 for fail.
44+
45+
"""
46+
try:
47+
import pytest
48+
except ImportError:
49+
raise RuntimeError('Testing module `pytest` is not installed. Run `conda install pytest`')
50+
abs_test_dir = os.path.sep.join([os.path.abspath(os.path.dirname(__file__)), "tests"])
51+
52+
command = ['-rws', '-v']
53+
if extent.lower() in ['smoke', 'quick']:
54+
command.extend(['-m', 'quick'])
55+
elif extent.lower() == 'full':
56+
command.extend(['-m', 'not long'])
57+
elif extent.lower() == 'long':
58+
pass
59+
if extras is not None:
60+
command.extend(extras)
61+
command.extend(['--capture=sys', abs_test_dir])
62+
63+
retcode = pytest.main(command)
64+
return retcode

0 commit comments

Comments
 (0)