Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@
/include/
tags
build*/
/installed/
/install*/
/cmake-build-debug/
compilation.log

comp*.log
/lib
.DS_Store
__pycache__/
*.pyc
*.pyo
9 changes: 9 additions & 0 deletions cpp.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rm -rf build
rm -rf installed

cmake -S . -B build \
-D CMAKE_INSTALL_PREFIX=$LIBEFP_DIR/installed \
-D BUILD_SHARED_LIBS=ON \
-D LIBEFP_ENABLE_OPENMP=ON

cmake --build build --target install
3 changes: 2 additions & 1 deletion efpmd/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ static void state_init(struct state *state, const struct cfg *cfg, const struct
state->energy = 0;
state->grad = xcalloc(sys->n_frags * 6 + sys->n_charges * 3, sizeof(double));
state->ff = NULL;
state->torch = NULL;
state->torch = NULL;
state->torch_grad = NULL;

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

Expand Down
26 changes: 26 additions & 0 deletions lib/pylibefp/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# @BEGIN LICENSE
#
# pylibefp/__init__.py:
#
# Copyright (c) 2017-2019 The Psi4 Developers
#
# All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
#
# @END LICENSE
#

import os
pylibefp_module_loc = os.path.dirname(os.path.abspath(__file__))

# Init core
from . import core

# Load driver and version paraphernalia
from .wrapper import from_dict, to_dict
from .exceptions import EFPException, Fatal, NoMemory, FileNotFound, EFPSyntaxError, UnknownFragment, PolNotConverged, PyEFPSyntaxError
__version__ = "2.0.0"

# A few extraneous functions
from .extras import test
Binary file added lib/pylibefp/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file added lib/pylibefp/__pycache__/extras.cpython-312.pyc
Binary file not shown.
Binary file added lib/pylibefp/__pycache__/wrapper.cpython-312.pyc
Binary file not shown.
68 changes: 68 additions & 0 deletions lib/pylibefp/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#
# @BEGIN LICENSE
#
# pylibefp/wrapper/exceptions.py:
#
# Copyright (c) 2017-2019 The Psi4 Developers
#
# All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
#
# @END LICENSE
#
"""Module with non-generic exceptions classes."""
from . import extras


class EFPException(Exception):
"""Error class for pylibefp."""
extras._success_flag_ = False


class Fatal(EFPException):
"""Fatal error has occurred."""
def __init__(self, msg):
EFPException.__init__(self, msg)
self.message = r"""\nEFPException: Fatal error has occurred. {}\n\n""".format(repr(msg))


class NoMemory(EFPException):
"""Insufficient memory."""
def __init__(self, msg):
EFPException.__init__(self, msg)
self.message = r"""\nEFPException: Insufficient memory. {}\n\n""".format(repr(msg))


class FileNotFound(EFPException):
"""File not found."""
def __init__(self, msg):
EFPException.__init__(self, msg)
self.message = r"""\nEFPException: File not found. {}\n\n""".format(repr(msg))


class EFPSyntaxError(EFPException):
"""Syntax error."""
def __init__(self, msg):
EFPException.__init__(self, msg)
self.message = r"""\nEFPException: Libefp syntax error. {}\n\n""".format(repr(msg))


class UnknownFragment(EFPException):
"""Unknown EFP fragment."""
def __init__(self, msg):
EFPException.__init__(self, msg)
self.message = r"""\nEFPException: Unknown EFP fragment. {}\n\n""".format(repr(msg))


class PolNotConverged(EFPException):
"""Polarization SCF procedure did not converge."""
def __init__(self, msg):
EFPException.__init__(self, msg)
self.message = r"""\nEFPException: Polarization SCF procedure did not converge. {}\n\n""".format(repr(msg))


class PyEFPSyntaxError(EFPException):
"""Syntax error."""
def __init__(self, msg):
EFPException.__init__(self, msg)
self.message = r"""\nEFPException: Pylibefp syntax error. {}\n\n""".format(repr(msg))
64 changes: 64 additions & 0 deletions lib/pylibefp/extras.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#
# @BEGIN LICENSE
#
# pylibefp/extras.py:
#
# Copyright (c) 2017-2019 The Psi4 Developers
#
# All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.
#
# @END LICENSE
#

import os

_success_flag_ = False

### # Working directory
### _input_dir_ = os.getcwd()
###
### def get_input_directory():
### return _input_dir_


# Testing
def test(extent='full', extras=None):
"""Runs a test suite through pytest.

Parameters
----------
extent : {'smoke', 'quick', 'full', 'long'}
All choices are defined, but choices may be redundant in some projects.
_smoke_ will be minimal "is-working?" test(s).
_quick_ will be as much coverage as can be got quickly, approx. 1/3 tests.
_full_ will be the whole test suite, less some exceedingly long outliers.
_long_ will be the whole test suite.
extras : list
Additional arguments to pass to `pytest`.

Returns
-------
int
Return code from `pytest.main()`. 0 for pass, 1 for fail.

"""
try:
import pytest
except ImportError:
raise RuntimeError('Testing module `pytest` is not installed. Run `conda install pytest`')
abs_test_dir = os.path.sep.join([os.path.abspath(os.path.dirname(__file__)), "tests"])

command = ['-rws', '-v']
if extent.lower() in ['smoke', 'quick']:
command.extend(['-m', 'quick'])
elif extent.lower() == 'full':
command.extend(['-m', 'not long'])
elif extent.lower() == 'long':
pass
if extras is not None:
command.extend(extras)
command.extend(['--capture=sys', abs_test_dir])

retcode = pytest.main(command)
return retcode
19 changes: 19 additions & 0 deletions lib/pylibefp/tests/addons.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest

from qcelemental.util import which_import, parse_version


def is_psi4_new_enough(version_feature_introduced):
if which_import('psi4') is None:
return False
import psi4
return parse_version(psi4.__version__) >= parse_version(version_feature_introduced)


using_psi4 = pytest.mark.skipif(
which_import('psi4', return_bool=True) is False,
reason='Not detecting package psi4. Install package if necessary and and to envvar PYTHONPATH')

using_psi4_efpmints = pytest.mark.skipif(
is_psi4_new_enough("1.2a1.dev507") is False,
reason="Psi4 does not include EFP integrals in mints. Update to development head")
15 changes: 15 additions & 0 deletions lib/pylibefp/tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest


@pytest.fixture(scope="session", autouse=True)
def set_up_overall(request):
pass


@pytest.fixture(scope="function", autouse=True)
def set_up():
pass


def tear_down():
pass
147 changes: 147 additions & 0 deletions lib/pylibefp/tests/systems.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import pylibefp
#from utils import *

b2a = 0.529177
a2b = 1.0 / b2a


def system_1():
sys = pylibefp.core.efp()

frags = ['h2o_l', 'nh3_l'] # specifying LIBRARY with _l for variety
sys.add_potential(frags)
sys.add_fragment(frags)
sys.set_frag_coordinates(0, 'xyzabc', [0.0 * a2b, 0.0 * a2b, 0.0 * a2b, 1.0, 2.0, 3.0]) # yapf: disable
sys.set_frag_coordinates(1, 'xyzabc', [5.0 * a2b, 0.0 * a2b, 0.0 * a2b, 5.0, 2.0, 8.0]) # yapf: disable

sys.prepare()
return sys


def system_2():
sys = pylibefp.core.efp()

frags = ['h2o_l', 'nh3_l', 'h2o_l', 'h2o_l', 'nh3_l']
sys.add_potential(frags)
sys.add_fragment(frags)
sys.set_frag_coordinates(0, 'xyzabc', [-1.0 * a2b, 3.7 * a2b, 0.4 * a2b, -1.3, 0.0, 7.0]) # yapf: disable
sys.set_frag_coordinates(1, 'xyzabc', [ 0.4 * a2b, -0.9 * a2b, -0.7 * a2b, 4.0, 1.6, -2.3]) # yapf: disable
sys.set_frag_coordinates(2, 'xyzabc', [ 1.7 * a2b, 2.0 * a2b, 3.3 * a2b, -1.2, -2.0, 6.2]) # yapf: disable
sys.set_frag_coordinates(3, 'xyzabc', [ 0.0 * a2b, 3.9 * a2b, -3.4 * a2b, 1.3, 5.2, -3.0]) # yapf: disable
sys.set_frag_coordinates(4, 'xyzabc', [-3.5 * a2b, 0.0 * a2b, -0.7 * a2b, 0.0, -2.7, 2.7]) # yapf: disable

sys.prepare()
return sys


def system_3():
sys = pylibefp.core.efp()

frags = ['h2o_l', 'nh3_l', 'nh3_l', 'nh3_l', 'ch3oh_l', 'h2o_l', 'h2o_l', 'ch3oh_l', 'h2o_l']
sys.add_potential(frags)
sys.add_fragment(frags)
sys.set_frag_coordinates(
0, 'points', [i * a2b for i in [-3.394, -1.900, -3.700, -3.524, -1.089, -3.147, -2.544, -2.340, -3.445]])
sys.set_frag_coordinates(1, 'points',
[i * a2b for i in [-5.515, 1.083, 0.968, -5.161, 0.130, 0.813, -4.833, 1.766, 0.609]])
sys.set_frag_coordinates(2, 'points',
[i * a2b for i in [1.848, 0.114, 0.130, 1.966, 0.674, -0.726, 0.909, 0.273, 0.517]])
sys.set_frag_coordinates(3, 'points',
[i * a2b for i in [-1.111, -0.084, -4.017, -1.941, 0.488, -3.813, -0.292, 0.525, -4.138]])
sys.set_frag_coordinates(4, 'points',
[i * a2b for i in [-2.056, 0.767, -0.301, -2.999, -0.274, -0.551, -1.201, 0.360, 0.258]])
sys.set_frag_coordinates(5, 'points',
[i * a2b for i in [-0.126, -2.228, -0.815, 0.310, -2.476, 0.037, 0.053, -1.277, -1.011]])
sys.set_frag_coordinates(6, 'points',
[i * a2b for i in [-1.850, 1.697, 3.172, -1.050, 1.592, 2.599, -2.666, 1.643, 2.614]])
sys.set_frag_coordinates(7, 'points',
[i * a2b for i in [1.275, -2.447, -4.673, 0.709, -3.191, -3.592, 2.213, -1.978, -4.343]])
sys.set_frag_coordinates(
8, 'points', [i * a2b for i in [-5.773, -1.738, -0.926, -5.017, -1.960, -1.522, -5.469, -1.766, 0.014]])

sys.prepare()
return sys


def system_4():
sys = pylibefp.core.efp()

frags = ['acetone_l', 'c2h5oh_l', 'c6h6_l', 'ccl4_l', 'ch3oh_l', 'ch4_l', 'cl2_l', 'dcm_l', 'dmso_l', 'h2_l', 'h2o_l', 'nh3_l']
sys.add_potential(frags)
sys.add_fragment(frags)
sys.set_frag_coordinates(0, 'xyzabc', [ 0.0 * a2b, 0.0 * a2b, 0.0 * a2b, 0.0, 0.2, 0.3]) # yapf: disable
sys.set_frag_coordinates(1, 'xyzabc', [ 7.0 * a2b, 0.0 * a2b, 0.0 * a2b, 0.0, 2.0, 3.7]) # yapf: disable
sys.set_frag_coordinates(2, 'xyzabc', [ 14.0 * a2b, 0.0 * a2b, 0.0 * a2b, 3.1, 0.8, 2.0]) # yapf: disable
sys.set_frag_coordinates(3, 'xyzabc', [ 21.0 * a2b, 0.0 * a2b, 0.0 * a2b, 0.0, 8.0, 0.0]) # yapf: disable
sys.set_frag_coordinates(4, 'xyzabc', [ 0.0 * a2b, 6.0 * a2b, 0.0 * a2b, 0.7, 2.0, 1.0]) # yapf: disable
sys.set_frag_coordinates(5, 'xyzabc', [ 7.0 * a2b, 6.0 * a2b, 0.0 * a2b, 0.6, 0.0, 4.7]) # yapf: disable
sys.set_frag_coordinates(6, 'xyzabc', [ 14.0 * a2b, 6.0 * a2b, 0.0 * a2b, 0.0, 0.0, 0.3]) # yapf: disable
sys.set_frag_coordinates(7, 'xyzabc', [ 21.0 * a2b, 6.0 * a2b, 0.0 * a2b, 0.0, 0.4, 0.3]) # yapf: disable
sys.set_frag_coordinates(8, 'xyzabc', [ 0.0 * a2b, 12.0 * a2b, 0.0 * a2b, 0.8, 0.0, 0.0]) # yapf: disable
sys.set_frag_coordinates(9, 'xyzabc', [ 7.0 * a2b, 12.0 * a2b, 0.0 * a2b, 8.0, 0.7, 0.8]) # yapf: disable
sys.set_frag_coordinates(10, 'xyzabc', [ 14.0 * a2b, 12.0 * a2b, 0.0 * a2b, 0.0, 0.0, 0.0]) # yapf: disable
sys.set_frag_coordinates(11, 'xyzabc', [ 21.0 * a2b, 12.0 * a2b, 0.0 * a2b, 0.0, 2.0, 0.0]) # yapf: disable

sys.prepare()
return sys


def system_5():
sys = pylibefp.core.efp()

frags = ['h2o_l', 'nh3_l']
sys.add_potential(frags)
sys.add_fragment(frags)
sys.set_frag_coordinates(0, 'xyzabc', [ 0.0 * a2b, 0.0 * a2b, 0.0 * a2b, 3.0, 0.0, 7.0]) # yapf: disable
sys.set_frag_coordinates(1, 'xyzabc', [ 18.0 * a2b, 18.0 * a2b, 18.0 * a2b, 5.0, 4.0, 6.0]) # yapf: disable

sys.prepare()
return sys


def system_6():
sys = pylibefp.core.efp()

frags = ['h2o_l', 'ch3oh_l', 'h2o_l', 'ch3oh_l', 'nh3_l']
sys.add_potential(frags)
sys.add_fragment(frags)
sys.set_frag_coordinates(0, 'xyzabc', [ 0.0 * a2b, 0.0 * a2b, 0.0 * a2b, 0.0, 0.0, 0.0]) # yapf: disable
sys.set_frag_coordinates(1, 'xyzabc', [ 19.0 * a2b, 0.0 * a2b, 0.0 * a2b, 0.0, 0.0, 0.0]) # yapf: disable
sys.set_frag_coordinates(2, 'xyzabc', [ 0.0 * a2b, 19.0 * a2b, 0.0 * a2b, 0.0, 0.0, 0.0]) # yapf: disable
sys.set_frag_coordinates(3, 'xyzabc', [ 0.0 * a2b, 0.0 * a2b, 19.0 * a2b, 0.0, 0.0, 0.0]) # yapf: disable
sys.set_frag_coordinates(4, 'xyzabc', [ 18.0 * a2b, 18.0 * a2b, 18.0 * a2b, 0.0, 0.0, 0.0]) # yapf: disable

sys.prepare()
return sys


def system_qm1():
sys = pylibefp.core.efp()

frags = ['h2o_l', 'c6h6_l', 'nh3_l']
sys.add_potential(frags)
sys.add_fragment(frags)
sys.set_frag_coordinates(0, 'xyzabc', [ -1.6 * a2b, 4.7 * a2b, 1.4 * a2b, -1.3, 0.1, 7.0]) # yapf: disable
sys.set_frag_coordinates(1, 'xyzabc', [ 0.4 * a2b, -0.9 * a2b, -0.7 * a2b, 2.3, 1.6, -2.3]) # yapf: disable
sys.set_frag_coordinates(2, 'xyzabc', [ -3.5 * a2b, -2.0 * a2b, -0.7 * a2b, 0.0, 2.2, 2.7]) # yapf: disable

sys.prepare()
return sys


def system_qm2():
sys = pylibefp.core.efp()

frags = ['ch3oh_l', 'dmso_l', 'dmso_l', 'acetone_l', 'dcm_l', 'acetone_l', 'acetone_l']
sys.add_potential(frags)
sys.add_fragment(frags)
sys.set_frag_coordinates(0, 'xyzabc', [ 0.0 * a2b, -1.0 * a2b, 0.0 * a2b, 0.0, 1.1, 2.0]) # yapf: disable
sys.set_frag_coordinates(1, 'xyzabc', [ -5.0 * a2b, 12.0 * a2b, 0.0 * a2b, 3.0, 0.2, 5.0]) # yapf: disable
sys.set_frag_coordinates(2, 'xyzabc', [ 0.0 * a2b, -3.0 * a2b, 5.0 * a2b, 6.0, 2.3, 8.0]) # yapf: disable
sys.set_frag_coordinates(3, 'xyzabc', [ -5.0 * a2b, -4.0 * a2b, -5.0 * a2b, 9.0, 0.4, 1.0]) # yapf: disable
sys.set_frag_coordinates(4, 'xyzabc', [ -9.0 * a2b, -5.0 * a2b, 1.0 * a2b, 2.0, 1.5, 4.0]) # yapf: disable
sys.set_frag_coordinates(5, 'xyzabc', [ 7.0 * a2b, -2.0 * a2b, 11.0 * a2b, 5.0, 0.6, 7.0]) # yapf: disable
sys.set_frag_coordinates(6, 'xyzabc', [ -9.0 * a2b, -7.0 * a2b, -9.0 * a2b, 8.0, 2.7, 0.0]) # yapf: disable

sys.prepare()
return sys
Loading
Loading