Skip to content

Commit

Permalink
Merge pull request #48 from calpolyccg/nix-poetry
Browse files Browse the repository at this point in the history
Add a Nix development enviornment to MD-SAPT
  • Loading branch information
ALescoulie authored Jun 13, 2024
2 parents 927d015 + b52cd7f commit 2d684e1
Show file tree
Hide file tree
Showing 8 changed files with 2,352 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
use flake

5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,8 @@ ENV/
# MDSAPT-generated files
timer.dat
input.yaml
*.out

# Direnv files
.direnv/

19 changes: 19 additions & 0 deletions docs/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,22 @@ To ensure it's been installed correctly, run `mdsapt` or `python3 -m mdsapt`.
Commands:
generate Generate a template input file at filename.
run Run a SAPT calculation using the configuration in in_file.
Creating a Development Environment
__________________________________

Using Nix
^^^^^^^^^

Make sure you have the `nix package manager <https://nixos.wiki/wiki/Nix_package_manager>`_ installed and clone the repository.
The development shell can be entered with the following commands, but note that the initial build it will take a long time to complete.

.. code-block:: bash
git clone https://github.com/calpolyccg/MDSAPT.git
cd MDSAPT
nix develop
Alternatively if you have `direnv <https://direnv.net/>`_ you will simply be promoted to approve the directory, then the environment will be built, this method has the advantage of being automatically applied when you enter the MDSAPT directory

224 changes: 224 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
description = "SAPT energy calculator built using MDAnalysis and Psi4 ";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
poetry2nix.url = "github:nix-community/poetry2nix";
qchem.url = "github:Nix-QChem/NixOS-QChem";
};

outputs = { self, nixpkgs, flake-utils, poetry2nix, qchem }:
flake-utils.lib.eachDefaultSystem (system:
let
lib = nixpkgs.lib;

pkgs = import nixpkgs {
system = system;
overlays = [
qchem.overlays.qchem
poetry2nix.overlays.default
];
};


# Build dependencies for pacakges
pypkgs-build-reqs = {
mdanalysis = [ "setuptools" ];
mda-xdrlib = [ "setuptools" ];
mmtf-python = [ "setuptools" ];
mrcfile = [ "setuptools" ];
griddataformats = [ "setuptools" ];
pyright = [ "setuptools" ];
#matplotlib = [ "pybind11" ];
#scipy = [ "setuptools" "wheel" "pybind11" "pythran" ];
};

p2n-overrides = pkgs.poetry2nix.defaultPoetryOverrides.extend (final: prev:
builtins.mapAttrs (package: build-reqs:
(builtins.getAttr package prev).overridePythonAttrs (old: {
buildInputs = (old.buildInputs or [ ]) ++ (builtins.map (pkg: if builtins.isString pkg then builtins.getAttr pkg prev else pkg) build-reqs);
})
) pypkgs-build-reqs
);

unfuckScipy = final: prev: {
scipy = pkgs.python311Packages.scipy;
};

unfuckNumpy = final: prev: {
numpy = pkgs.python311Packages.numpy;
};

python = pkgs.python311.override {
packageOverrides = unfuckScipy;
};

poetryEnv = pkgs.poetry2nix.mkPoetryEnv {
projectDir = ./.;
python = python;
overrides = [ p2n-overrides unfuckScipy unfuckNumpy ]; #unfuckScipy ];
};

devEnv = pkgs.mkShell {
propagatedBuildInputs = [ poetryEnv];
buildInputs = with pkgs; [pkgs.qchem.psi4 pkgs.qchem.openmm pkgs.qchem.pdbfixer ];
};

# DON'T FORGET TO PUT YOUR PACKAGE NAME HERE, REMOVING `throw`
packageName = "MD-SAPT";

in {
devShells.default = devEnv;
});
}

28 changes: 11 additions & 17 deletions mdsapt/tests/test_sapt.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,26 @@
from ..config import Config, load_from_yaml_file
from ..sapt import TrajectorySAPT, DockingSAPT

traj_settings = load_from_yaml_file(
os.path.join(os.getcwd(), 'mdsapt', 'tests', 'testing_resources', 'test_input.yaml'))

dock_settings = load_from_yaml_file(
os.path.join(os.getcwd(), 'mdsapt', 'tests', 'testing_resources', 'docking_in.yaml'))

unv = traj_settings.analysis.create_universe()
elements = guess_types(unv.atoms.names)
unv.add_TopologyAttr('elements', elements)

class TestSAPT:
"""
Test object for SAPT analysis
"""
traj_settings: Config
dock_settings: Config
unv: MDAnalysis.Universe

def setup(self) -> None:
"""
Sets up system and config for other tests
"""
self.traj_settings = load_from_yaml_file(
os.path.join(os.getcwd(), 'mdsapt', 'tests', 'testing_resources', 'test_input.yaml'))
self.dock_settings = load_from_yaml_file(
os.path.join(os.getcwd(), 'mdsapt', 'tests', 'testing_resources', 'docking_in.yaml'))
self.unv = self.traj_settings.analysis.create_universe()
elements = guess_types(self.unv.atoms.names)
self.unv.add_TopologyAttr('elements', elements)

def test_run_traj_sapt(self) -> None:
"""
Test running trajectory SAPT
"""
sapt12 = TrajectorySAPT(self.traj_settings)
sapt12 = TrajectorySAPT(traj_settings)
sapt12.run(1, 2)
cols_act = sapt12.results.columns
cols_exp = ['residues', 'time', 'total', 'electrostatic',
Expand All @@ -47,7 +41,7 @@ def test_run_dock_sapt(self) -> None:
"""
Test running docking SAPT
"""
docking = DockingSAPT(self.dock_settings)
docking = DockingSAPT(dock_settings)
docking.run()
cols_act = docking.results.columns
cols_exp = ['structure', 'pair', 'total', 'electrostatic',
Expand Down
Loading

0 comments on commit 2d684e1

Please sign in to comment.