Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial test. [Fixes #10] #13

Merged
merged 24 commits into from
Jun 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
with:
python-version: ${{ matrix.python-version }}
environment-file: devtools/conda-envs/test_env.yaml
mamba-version: "*"
# mamba-version: "*"
channels: conda-forge, defaults

activate-environment: test
Expand Down
3 changes: 1 addition & 2 deletions mdakit_membcurv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
Handles the primary functions
"""

from .lib.mods import *
from .lib.mods import dict2pickle, core_fast, curvature
import sys
import os
import time
import argparse
import mdtraj as md
import MDAnalysis as mda
import math
Expand Down
Binary file added mdakit_membcurv/data/test_curvature_abca1.xtc
Binary file not shown.
11,004 changes: 11,004 additions & 0 deletions mdakit_membcurv/data/test_curvature_po4_only.gro

Large diffs are not rendered by default.

Binary file added mdakit_membcurv/data/test_curvature_po4_only.xtc
Binary file not shown.
91 changes: 2 additions & 89 deletions mdakit_membcurv/lib/mods.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,7 @@
#from collections import OrderedDict
#from itertools import permutations
import itertools as it
import mdtraj as md
import numpy as np
import argparse
import pickle
import textwrap
import time
import math
import os
import re


class Grid:
Expand Down Expand Up @@ -111,37 +103,6 @@ def list_head_beads(self):
return def_po4_beads(self.lipid_types, self.leaflets, self.head_index, self.top)


def input_options():
"""
Command line arguments as input_options
"""

#usage = (" [options] < input > output")
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter,
description=textwrap.dedent('''\
Trial version KHURV.py | To calculate Gaussian (K) and mean (H) curvature from MD simulations
'''))

parser.add_argument(
"-f", metavar="<GRO INPUT FILE>", help="Input gro file.")
parser.add_argument(
"-x", metavar="<XTC INPUT>", help='Input trajectory.')
parser.add_argument(
"-io", type=str, metavar='<INDEX OUTER LEAFLET begin:end>', help='Index range outer leaflet.')
parser.add_argument(
"-ii", type=str, metavar='<INDEX INNER LEAFLET begin:end>', help='Index range inner leaflet.')
parser.add_argument(
"-uw", type=int, default=5, metavar='UNIT CELL WIDTH', help="Unit cell width in nm. Default: %(default)s .")
parser.add_argument("-name", type=str, metavar='<PREFIX NAME>', default='system',
help="System name. Prefix used in OUTPUT K_G AND K_H files.")
parser.add_argument(
"-sk", type=int, default=10, metavar="<n>", help="Skip frames. Default: ")
parser.add_argument("-out", type=str, metavar="<OUTPUT DIR>", default='output/',
help='Output file directory. Default: %(default)s')

return parser


def parse_range(astr):
"""
Split range provided by user
Expand Down Expand Up @@ -213,40 +174,6 @@ def def_all_beads(lipid_types, leaflets, head_list, topology):
return dic_all_beads


def xy2cell(coords, n_cells, max_width, bead, grid):
"""
Maps coordinates to indexed unit grid of size `max_width`.

(x,y) |---> [i,j]


Parameters
----------
coords : tuple.
(x,y) coordinates of `bead`.
n_cells : int.
number of cells in the grid of size `max_width`.
max_width : int.
Maximum width of simulation box. Determines size of grid.
bead : int.
Element in reference group.


Returns
-------
{ grid[i,j] } : dict
Dictionary with [i,j] tuples.

"""

grid[
math.floor((abs(coords[0]) / max_width * n_cells)),
math.floor((abs(coords[1]) / max_width * n_cells))
].append(bead)

return grid


def dict2pickle(name, dict_):
"""
Exports values stored in a dictionary to a pickle file.
Expand Down Expand Up @@ -307,15 +234,15 @@ def core_fast(traj, jump, n_cells, leaflets, lipid_types, lipid_ref,

for leaflet in leaflets:
core_fast_leaflet(z_ref[leaflet], leaflet, traj, jump, n_cells,
lipid_types, lipid_ref, box_size, max_width)
lipid_types, lipid_ref, max_width)

dict2pickle(prefix, z_ref)

return z_ref


def core_fast_leaflet(z_Ref, leaflet, traj, jump, n_cells, lipid_types,
lipid_ref, box_size, max_width):
lipid_ref, max_width):
"""
Runs core_fast_leaflet for each leaflet

Expand Down Expand Up @@ -444,8 +371,6 @@ def mean_curvature(Z):
def curvature(dict_reference, leaflets, n_cells):
"""
Calculates mean curvature from Z cloud points.


Parameters
----------
dict_reference : dict { [index]:[z_coords]}.
Expand All @@ -454,14 +379,11 @@ def curvature(dict_reference, leaflets, n_cells):
Leaflets of bilayer.
n_cells : int. default 20.
Number of cells in grid.


Returns
-------
K, H : 2d-array, 2d-array
Returns 2-dimensional array objects for mean
and gaussian curvature, respectively.

"""

H, K = [{key2: [] for key2 in leaflets} for i in range(2)]
Expand All @@ -479,12 +401,3 @@ def curvature(dict_reference, leaflets, n_cells):
else:
print('No interpolation performed. Plot may display empty values.')
return H, K


def timer(current_time, start_time):

elapsed_time = current_time - start_time
m, s = divmod(elapsed_time, 60)
h, m = divmod(m, 60)
print('Elapsed time:', elapsed_time)
print("%d:%02d:%02d" % (h, m, s))
23 changes: 23 additions & 0 deletions mdakit_membcurv/tests/datafiles.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@


"""
Location of datafiles for Membrane Curvature unit tests
=======================================================

MD simulations files stored in `data` sub-directory.

from mdakit_membcurv.datafiles import *
"""

__all__ = [
"GRO_MEMBRANE_PROTEIN", # Gromacs file of POPC POPE CHOL membrane
"XTC_MEMBRANE_PROTEIN" # Gromacs trajectory of 10 frames.
]

from pkg_resources import resource_filename

GRO_MEMBRANE_PROTEIN = resource_filename(__name__, '../data/test_curvature_abca1.gro')
GRO_PO4 = resource_filename(__name__, '../data/test_curvature_po4_only.gro')
XTC_MEMBRANE_PROTEIN = resource_filename(__name__, '../data/test_curvature_abca1.xtc')
XTC_PO4 = resource_filename(__name__, '../data/test_curvature_po4_only.xtc')
del resource_filename
Binary file removed mdakit_membcurv/tests/test_curvature_abca1.xtc
Binary file not shown.