From 3e87eec5f6ef8abe226efedc56c9491ab56b5b73 Mon Sep 17 00:00:00 2001 From: Estefania Barreto-Ojeda Date: Mon, 5 Jul 2021 22:47:44 -0600 Subject: [PATCH] Added explicit imports. (#44) * Explicit imports added. Folder reorganization. --- membrane_curvature/__init__.py | 3 +- membrane_curvature/core.py | 7 ++- membrane_curvature/curvature.py | 54 +++++++++++++++++++ .../{lib/mods.py => surface.py} | 50 ----------------- ...membcurv.py => test_membrane_curvature.py} | 3 +- 5 files changed, 61 insertions(+), 56 deletions(-) create mode 100644 membrane_curvature/curvature.py rename membrane_curvature/{lib/mods.py => surface.py} (77%) rename membrane_curvature/tests/{test_mdakit_membcurv.py => test_membrane_curvature.py} (98%) diff --git a/membrane_curvature/__init__.py b/membrane_curvature/__init__.py index 38923a2..c803aeb 100644 --- a/membrane_curvature/__init__.py +++ b/membrane_curvature/__init__.py @@ -4,7 +4,8 @@ """ # Add imports here -from .core import * +from membrane_curvature.surface import normalized_grid, derive_surface, get_z_surface +from membrane_curvature.curvature import mean_curvature, gaussian_curvature # Handle versioneer from ._version import get_versions diff --git a/membrane_curvature/core.py b/membrane_curvature/core.py index da0a66f..8883003 100644 --- a/membrane_curvature/core.py +++ b/membrane_curvature/core.py @@ -5,7 +5,8 @@ Handles the primary functions """ -from .lib.mods import derive_surface, gaussian_curvature, mean_curvature +from membrane_curvature.surface import normalized_grid, derive_surface, get_z_surface +from membrane_curvature.curvature import mean_curvature, gaussian_curvature import time import MDAnalysis as mda import math @@ -16,7 +17,7 @@ def main(): - start_time = time.time() + # 1. Populate universe with coordinates and trajectory u = mda.Universe(topology, trajectory) @@ -38,8 +39,6 @@ def main(): K = gaussian_curvature(z_coords) H = mean_curvature(z_coords) - timer(time.time(), start_time) - return diff --git a/membrane_curvature/curvature.py b/membrane_curvature/curvature.py new file mode 100644 index 0000000..6ff8e26 --- /dev/null +++ b/membrane_curvature/curvature.py @@ -0,0 +1,54 @@ +import numpy as np + + +def gaussian_curvature(Z): + """ + Calculate gaussian curvature from Z cloud points. + + + Parameters + ---------- + Z : Numpy array, cloud of points. + + + Returns + ------- + K : 2d-array + Returns 2-dimensional array object with values of mean curvature. + + """ + + Zy, Zx = np.gradient(Z) + Zxy, Zxx = np.gradient(Zx) + Zyy, _ = np.gradient(Zy) + + K = (Zxx * Zyy - (Zxy ** 2)) / (1 + (Zx ** 2) + (Zy ** 2)) ** 2 + + return K + + +def mean_curvature(Z): + """ + Calculates mean curvature from Z cloud points. + + + Parameters + ---------- + Z : Numpy array, cloud of points. + + + Returns + ------- + H : 2d-array + Returns 2-dimensional array object with values of gaussian curvature. + + """ + + Zy, Zx = np.gradient(Z) + Zxy, Zxx = np.gradient(Zx) + Zyy, _ = np.gradient(Zy) + + H = (Zx**2 + 1) * Zyy - 2 * Zx * Zy * Zxy + (Zy**2 + 1) * Zxx + H = -H / (2 * (Zx**2 + Zy**2 + 1)**(1.5)) + + return H diff --git a/membrane_curvature/lib/mods.py b/membrane_curvature/surface.py similarity index 77% rename from membrane_curvature/lib/mods.py rename to membrane_curvature/surface.py index b6751c0..17c3b76 100644 --- a/membrane_curvature/lib/mods.py +++ b/membrane_curvature/surface.py @@ -107,54 +107,4 @@ def normalized_grid(grid_z_coordinates, grid_norm_unit): return z_normalized -def gaussian_curvature(Z): - """ - Calculate gaussian curvature from Z cloud points. - - - Parameters - ---------- - Z : Numpy array, cloud of points. - - - Returns - ------- - K : 2d-array - Returns 2-dimensional array object with values of mean curvature. - - """ - - Zy, Zx = np.gradient(Z) - Zxy, Zxx = np.gradient(Zx) - Zyy, _ = np.gradient(Zy) - - K = (Zxx * Zyy - (Zxy ** 2)) / (1 + (Zx ** 2) + (Zy ** 2)) ** 2 - - return K - - -def mean_curvature(Z): - """ - Calculates mean curvature from Z cloud points. - - - Parameters - ---------- - Z : Numpy array, cloud of points. - - - Returns - ------- - H : 2d-array - Returns 2-dimensional array object with values of gaussian curvature. - - """ - - Zy, Zx = np.gradient(Z) - Zxy, Zxx = np.gradient(Zx) - Zyy, _ = np.gradient(Zy) - - H = (Zx**2 + 1) * Zyy - 2 * Zx * Zy * Zxy + (Zy**2 + 1) * Zxx - H = -H / (2 * (Zx**2 + Zy**2 + 1)**(1.5)) - return H diff --git a/membrane_curvature/tests/test_mdakit_membcurv.py b/membrane_curvature/tests/test_membrane_curvature.py similarity index 98% rename from membrane_curvature/tests/test_mdakit_membcurv.py rename to membrane_curvature/tests/test_membrane_curvature.py index 563f8c0..0a5efb8 100644 --- a/membrane_curvature/tests/test_mdakit_membcurv.py +++ b/membrane_curvature/tests/test_membrane_curvature.py @@ -3,7 +3,8 @@ """ import pytest -from ..lib.mods import mean_curvature, gaussian_curvature, normalized_grid, derive_surface, get_z_surface +from membrane_curvature.surface import normalized_grid, derive_surface, get_z_surface +from membrane_curvature.curvature import mean_curvature, gaussian_curvature import numpy as np from numpy.testing import assert_almost_equal import MDAnalysis as mda