Skip to content

Commit

Permalink
Added explicit imports. (#44)
Browse files Browse the repository at this point in the history
* Explicit imports added. Folder reorganization.
  • Loading branch information
Estefania Barreto-Ojeda authored Jul 6, 2021
1 parent 687d869 commit 3e87eec
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 56 deletions.
3 changes: 2 additions & 1 deletion membrane_curvature/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions membrane_curvature/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +17,7 @@

def main():

start_time = time.time()


# 1. Populate universe with coordinates and trajectory
u = mda.Universe(topology, trajectory)
Expand All @@ -38,8 +39,6 @@ def main():
K = gaussian_curvature(z_coords)
H = mean_curvature(z_coords)

timer(time.time(), start_time)

return


Expand Down
54 changes: 54 additions & 0 deletions membrane_curvature/curvature.py
Original file line number Diff line number Diff line change
@@ -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
50 changes: 0 additions & 50 deletions membrane_curvature/lib/mods.py → membrane_curvature/surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3e87eec

Please sign in to comment.