API Documentation

class twodanalysis.MembProp.MembProp(obj, lipid_list=None, connection_chains=None, working_lip=None, verbose=False, forcefield='charmm')[source]

Bases: object

visualize_polarity(lipids='all')[source]

This function is used to visualize what atoms are considered in polarity

Parameters:

lipids (str, optional) – Lipids to show polarity, by default “all”

static extend_data(data, dimensions, percentage, others=None)[source]

Function to extent data for periodicity purposes

Parameters:
  • data (ndarray(:,2)) – data in 2D fashion

  • dimensions (ndarray(2)) – periodicity dimension (usually gottem from u.ts.dimensions[:2])

  • percentage (float) – Percentage of data to replicate with periodicity

  • others (list(ndarray(:), ndarray(:),…,ndarray(:)), optional) – List of other data to replicate with periodicity (ndarrays initially match with data axis 0 dimension), by default None

Returns:

  • ndarray – Data extended

  • ndarray, list – Data extended, others extended

cut_structure(structure, bond)[source]

Tool needed to cut structures in two parts based on a bond. This function is used to cut the structure in two parts based on a bond. It uses NetworkX to create a graph of the structure and then removes the bond. It then finds the connected components of the graph and returns the two parts. If the bond does not cut the structure into two parts, it raises a ValueError.

Parameters:
  • structure (MDAnalysis Universe or AtomGroup) – Any structure that we aim to cut

  • bond (tuple) – tuple with the names of the atoms of the bond we want to cut e.g. (“C21”, “C22”) or (“C31”, “C32”)

Returns:

part1, part2 – Two parts of the structure after cutting it based on the bond.

Return type:

NetworkX Graph

Raises:

ValueError – If the bond does not cut the structure into two parts, it raises a ValueError.

atgroup2nx(atgroup)[source]

Function to convert an MDAnalysis AtomGroup to a NetworkX Graph.

Parameters:

atgroup (MDAnalysis AtomGroup) – AtomGroup to convert

Returns:

Graph representing the structure of the AtomGroup

Return type:

NetworkX Graph

chain_structure(chain)[source]

Function to get the structure of the chain in the shape [C,Hi,Hj] for any nomemclature.

Parameters:

chain (NetworkX Graph) – Graph representing a lipid tail

Returns:

List containing various list of the form [C, Hi, Hj] where C is the carbon and Hi and Hj are the hydrogens connected to it.

Return type:

list

class twodanalysis.Cumulative2D.Cumulative2D(universe, lipid_list=None, verbose=False, edges=None, nbins=None, periodic=False, working_lip=None, connection_chains=None, forcefield='charmm')[source]

Bases: MembProp

order_matrix(lipid='DOPC', layer='top', nbins=None, n_chain=None, edges=None, start=None, final=None, step=1, method='numpy')[source]

Generates 2D SCD for specific lipids

Parameters:
  • lipid (str, optional) – Lipid to compute SCD, by default “DOPC”

  • layer (str, optional) – Layer to project in the 2D plane, by default “top”

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2]

  • n_chain (list(int), optional) – list with the number of carbons in each chain i.e., [16,18], by default None

  • edges (list(int), optional) – Edges for the 2D grid in the shape [xmin,xmax,ymin,ymax], by default None

  • start (int, optional) – Frame to start, by default None

  • final (int, optional) – Final frame to consider, by default None

  • step (int, optional) – Frames to skip, by defaulonnection_chains=connection_chains,t 1

  • method (str, optional) – Method to do the averages, by default “numpy”

Returns:

matrix containing the 2D SCD and list containing edges in the following disposition [v_min,v_max,v_min,_vmax] (Can be used to plot directly with extent)

Return type:

ndarray(n_grid,n_grid), list

histogram2D(sample1, weights, n_chain, bins=None, edges=None)[source]

Computes the 2D histogram of 2D data with various values taking an average of them

Parameters:
  • sample1 (np.array(n,2)) – 2D data information

  • weights (np.array(n,m)) – m values can be attached to the data (usually lenght of the tails)

  • n_chain (int or list) – Number of carbons in each chain, e.g, 16 or [16,16] for both chains

  • bins (int, optional) – Number of bins to split the space, by default 10

  • edges (list(float)) – Edges for the 2D grid in the shape [xmin,xmax,ymin,ymax]

Returns:

matrix containining the averaged 2D histogram, edges corresponding to te matrix

Return type:

np.array, list

numpyhistogram2D(sample1, weights, n_chain, bins=10, edges=None)[source]

Computes the 2D histogram of 2D data with various values taking an average of them

Parameters:
  • sample1 (np.array(n,2)) – 2D data information

  • weights (np.array(n,m)) – m values can be attached to the data (usually length of the tails)

  • n_chain (int or list) – Number of carbons in each chain, e.g, 16 or [16,16] for both chains

  • bins (int, optional) – Number of bins to split the space, by default 10

  • edges (list(float)) – Edges for the grid [xmin,xmax,ymin,ymax]

Returns:

matrix containing the averaged 2D histogram, edges corresponding to te matrix

Return type:

np.array, np.array

static count_order(data, min_lenght, n_chain)[source]

Function used to count and average the order parameter in each grid square

Parameters:
  • data (ndarray(n,2 + len(n_chain[0]) or 2 + len(n_chain[0]) +len(n_chain[1]))) – Array that contains the order parameters data to be averaged.

  • min_lenght (int) – size of the data

  • n_chain (int or list) – Sets the number of carbons in the fatty acida chain

Returns:

Array containing the mean SCD for each grid square

Return type:

_np.array

all_lip_order(layer, nbins=None, edges=None, start=None, final=None, step=None, chain='both')[source]

all_lip_order Find the 2D order parameters for all lipids

Parameters:
  • layer ((str)) – Layer, can be top, bot, both

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2]

  • edges (list(float)) – Edges for the grid in the shape [xmin,xmax,ymin,ymax]

  • start ((int, optional), optional) – start frame, by default None

  • final ((int, optional), optional) – final frame, by default None

  • step ((int, optional), optional) – step, by default 1

  • chain (str, optional) – If “sn1” computes order parameters for sn1 tail. If “sn2” computes order parameters for sn2 tail. If “both” computes order parameters for both tails as an average of both.

Returns:

matrix containing the 2d order, edges of the matrix

Return type:

ndarray(n,n), ndarray(n+1)

surface(start=None, final=None, step=None, lipid_list='DSPC', layer='top', function=None, splay=False)[source]

Code to loop over the trajectory and print [x,y,z(referenced to zmean), charge] in a file.

Parameters:
  • start (int, optional) – Start Frame, by default None

  • final (int, optional) – Final frame, by default None

  • step (int, optional) – Frames to skip, by default None

  • lipid_list (str or list, optional) – Lipid to work, by default “DSPC”

  • layer (str, optional) – Layer to work, by default ‘top’

  • function (function, optional) – Function that returns two arrays, the first with atomgroup.residues.resids, and the second with any property value. Defaults to None

  • splay (bool, optional) – Include or not splay angle computations, by default False

Returns:

Dataframe containing x,y,z,id,splay,function for each lipid

Return type:

pd.DataFrame

height_matrix(lipid_list, layer, edges=None, start=None, final=None, step=None, nbins=None)[source]

Code to divide the space in a 2D grid and compute the height referenced to zmean

Parameters:
  • lipid_list (list(str)) – Lipids to include in the height analysis

  • layer (str) – Working layer for heigt. It can be bot/top

  • edges (list) – Edges for the grid in the shape [xmin,xmax,ymin,ymax]

  • start (int, optional) – Frame to start analysis, by default None

  • final (int, optional) – Final frame for the analysis, by default None

  • step (int, optional) – Steps to skip, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2]

Returns:

Retun a matrix with the height information

Return type:

ndarray(nbins,nbins), edges

splay_matrix(lipid_list, layer, edges=None, start=None, final=None, step=None, nbins=None)[source]

Code to divide the space in a 2D grid and compute the splay angle

Parameters:
  • lipid_list (list(str)) – Lipids to include in the analysis

  • layer (str) – Working layer. Can be top/bot

  • edges (list) – Edges for the grid in the shape [xmin,xmax,ymin,ymax]

  • start (int, optional) – Frame to start analysis, by default None

  • final (int, optional) – Final frame for the analysis, by default None

  • step (int, optional) – Steps to skip, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2]

Returns:

Retun a matrix with the height information

Return type:

ndarray(nbins,nbins), edges

thickness(nbins=None, edges=None, lipid_list=None, start=None, final=None, step=None)[source]

Find the thickness mapped in a 2d grid

Parameters:
  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2]

  • edges (list) – Edges for the grid in the shape [xmin,xmax,ymin,ymax]

  • lipid_list (list(str)) – Lipids to be considered in the thickness computation

  • start (int, optional) – Start frame, by default None

  • final (int, optional) – Final frame, by default None

  • step (int, optional) – Step frame, by default None

Returns:

Matrix with the thickness, edeges for the matrix

Return type:

np.array(nbins,nbins), edges

project_property(function, layer='top', distribution=False, edges=None, start=None, final=None, step=None, nbins=None)[source]

Code to divide the space in a 2D grid and project the value of a property

Parameters:
  • function (function) – Function that takes mda.Atomgroup and returns two arrays: (1) array containing ids (2) array containing values for those ids

  • layer (str) – Working layer can be bot/top, defaults to “top”

  • distribution (bool) – If true compute the histogram instead of the averages. This is useful when someone wants to visualize the lipid lateral distribution over time.

  • edges (list(float)) – Edges for the grid in the shape [xmin,xmax,ymin,ymax]

  • start (int, optional) – Frame to start analysis, by default None

  • final (int, optional) – Final frame for the analysis, by default None

  • step (int, optional) – Steps to skip, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2]

Returns:

Retun a matrix with the height information

Return type:

ndarray(nbins,nbins), edges

class twodanalysis.Voronoi2D.Voronoi2D(universe, lipid_list=None, verbose=False, nbins=None, edges=None, connection_chains=None, working_lip=None, forcefield='charmm')[source]

Bases: MembProp

voronoi_properties(layer='top', working_lip=None, lipid_list=None, splay=False, function=None)[source]

Computes the APL for membranes with different lipids :Parameters: * layer (str, optional) – layer to compute the apl. It can be top/bot, by default ‘top’

  • working_lip (dict, optional) – dictionary mapping lipid and atoms to work for APL, by default None

  • lipid_list (list, optional) – list of lipids to be considered for APL, by default None

  • splay (bool,) – If True, it computes the splay angle for the lipids.

  • function (function:) – Function that takes mda. Atomgroup and returns two arrays: (1) array with ids (2) array with value of properties

Returns:

dictionary with vertices, areas, apl (if true), function values (if provided)

Return type:

dict

map_voronoi(voronoi_points, voronoi_property, nbins=None, edges=None)[source]

Function to map voronoi diagram to a 2D plane

Parameters:
  • voronoi_points (ndarray(:,2)) – [x,y] positions of the points to be considered in the voronoi plot

  • voronoi_property (ndarray(:)) – Areas corresponding to the points

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2] If None, it uses the default value of 180

  • edges (list(float)) – A list with the lipids of the grid [xmin,xmax,ymin,ymax], defaults to None

Returns:

numpy array (nbins,nbins), adn edges of this array

Return type:

ndarray, edges

voronoi_apl(layer='top', start=0, final=-1, step=1, lipid_list=None, nbins=None, edges=None)[source]

Function to compute and map the grid APL for several frames, map them to a 2D grid and average them

Parameters:
  • layer (str, optional) – working lipid layer, by default “top”

  • start (int, optional) – Frame to start, by default None. If None uses all the trajectory

  • final (int, optional) – final frame, by default None. If None uses all the trajectory

  • step (int, optional) – Frames to skip, by default None. If None uses all the trajectory

  • lipid_list (list, optional) – lipids involved in the computation, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2] If None, it uses the default value of 180

  • edges (list, optional) – A list with the limits of the grid [xmin,xmax,ymin,ymax]

Returns:

Array with the averaged 2D APL, edges

Return type:

ndarray

windows_apl(layer='top', start=0, final=-1, step=1, w_size=10, nbins=180)[source]

Function to compute APL and map it to a 2D grid in windows of time defined by the user.

Parameters:
  • layer (str, optional) – Wroking layer, by default “top”

  • start (int, optional) – Start Frame, by default 0

  • final (int, optional) – Final frame, by default -1

  • step (int, optional) – Frames to skip, by default 1

  • w_size (int, optional) – windows size (number of frames), by default 10

  • lipid_list (list, optional) – lipids to be included in the analysis, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2] If None, it uses the default value of 180

  • edges (list, optional) – list with the edges of the grid [xmin,xmax,ymin,ymax], by default None

Returns:

list with the windows averages between the start time and the final time, and edges of these matrices

Return type:

list(ndarrays(nbins,bins)), list

voronoi_thickness(start=None, final=None, step=None, lipid_list=None, nbins=None, edges=None)[source]

Function to compute and map the grid APL for several frames, map them to a 2D grid and average them

Parameters:
  • start (int, optional) – Frame to start, by default None. If None uses all the trajectory

  • final (int, optional) – final frame, by default None. If None uses all the trajectory

  • step (int, optional) – Frames to skip, by default None. If None uses all the trajectory

  • lipid_list (list, optional) – lipids involved in the computation, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2] If None, it uses the default value of 180

  • edges (list, optional) – A list with the limits of the grid [xmin,xmax,ymin,ymax]

Returns:

Array with the averaged 2D APL, edges

Return type:

ndarray

voronoi_height(layer='top', start=None, final=None, step=None, lipid_list=None, nbins=None, edges=None)[source]

Function to compute and map the grid height for several frames, map them to a 2D grid and average them

Parameters:
  • layer (str, optional) – working lipid layer, by default “top”

  • start (int, optional) – Frame to start, by default None. If None uses all the trajectory

  • final (int, optional) – final frame, by default None. If None uses all the trajectory

  • step (int, optional) – Frames to skip, by default None. If None uses all the trajectory

  • lipid_list (list, optional) – lipids involved in the computation, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2] If None, it uses the default value of 180

  • edges (list, optional) – A list with the limits of the grid [xmin,xmax,ymin,ymax]

Returns:

Array with the averaged 2D height, edges

Return type:

ndarray

voronoi_splay(layer='top', start=None, final=None, step=None, lipid_list=None, nbins=None, edges=None)[source]

Function to compute and map the grid splay angle for several frames, map them to a 2D grid and average them

Parameters:
  • layer (str, optional) – working lipid layer, by default “top”

  • start (int, optional) – Frame to start, by default None. If None uses all the trajectory

  • final (int, optional) – final frame, by default None. If None uses all the trajectory

  • step (int, optional) – Frames to skip, by default None. If None uses all the trajectory

  • lipid_list (list, optional) – lipids involved in the computation, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2] If None, it uses the default value of 180

  • edges (list, optional) – A list with the limits of the grid [xmin,xmax,ymin,ymax]

Returns:

Array with the averaged 2D splay angle, edges

Return type:

ndarray

voronoi_order(lipid, layer, n_chain=None, start=None, final=None, step=None, nbins=None, edges=None)[source]

Function to compute the order parameter for a given lipid in a given layer. It uses the voronoi tessalation to compute the order parameter and then maps it to a 2D grid. The order parameter is computed using the angles between the two chains of the lipid. The order parameter is defined as S = 1/2 * (3 * cos^2(theta) - 1) where theta is the angle between the two chains of the lipid. The order parameter is computed for each chain and then averaged to obtain the final order parameter.

Parameters:
  • lipid (str) – lipid to compute the order parameter

  • layer (str) – layer to compute the order parameter

  • n_chain (list(int), optional) – length of the chain involved in the computation, e.g., [16,18], by default None

  • start (int, optional) – Frame to start, by default None. If None uses all the trajectory

  • final (int, optional) – final frame, by default None. If None uses all the trajectory

  • step (int, optional) – Frames to skip, by default None. If None uses all the trajectory

  • lipid_list (list, optional) – lipids involved in the computation, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2] If None, it uses the default value of 180

  • edges (list, optional) – A list with the limits of the grid [xmin,xmax,ymin,ymax], by default None

Returns:

Array with the 2D order parameter, edges

Return type:

ndarray

voronoi_all_lip_order(lipid_list, layer, chain='both', start=None, final=None, step=None, nbins=None, edges=None)[source]

Function to compute the order parameter for all specified lipids (average them) in a given layer. It uses the voronoi tessalation to compute the order parameter and then maps it to a 2D grid. The order parameter is computed using the angles between the two chains of the lipid. The order parameter is defined as S = 1/2 * (3 * cos^2(theta) - 1) where theta is the angle between the two chains of the lipid.

Parameters:
  • lipid_list (list, optional) – lipids involved in the computation, by default None

  • layer (str) – layer to compute the order parameter

  • chain (str) – chain to compute the order parameter, by default “both”. It can be sn1/sn2/both

  • start (int, optional) – Frame to start, by default None. If None uses all the trajectory

  • final (int, optional) – final frame, by default None. If None uses all the trajectory

  • step (int, optional) – Frames to skip, by default None. If None uses all the trajectory

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2] If None, it uses the default value of 180

  • edges (list, optional) – A list with the limits of the grid [xmin,xmax,ymin,ymax], by default None

Returns:

Array with the 2D order parameter, edges

Return type:

ndarray

project_property(function, layer='top', start=None, final=None, step=None, nbins=None, edges=None)[source]

Function to compute and map the grid APL for several frames, map them to a 2D grid and average them

Parameters:
  • function (function) – Function that takes mda. Atomgroup and returns two arrays: (1) array with ids (2) array with value of properties

  • layer (str, optional) – working lipid layer, by default “top”

  • start (int, optional) – Frame to start, by default None. If None uses all the trajectory

  • final (int, optional) – final frame, by default None. If None uses all the trajectory

  • step (int, optional) – Frames to skip, by default None. If None uses all the trajectory

  • lipid_list (list, optional) – lipids involved in the computation, by default None

  • nbins (int or list, optional) – number of bins for the grid, by default None If int, it is the same for both dimensions. If list, it is a list with the number of bins for each dimension e.g., [nbins1, nbins2] If None, it uses the default value of 180

  • edges (list, optional) – A list with the limits of the grid [xmin,xmax,ymin,ymax]

Returns:

Array with the averaged 2D properties (coming from fuction), edges

Return type:

ndarray

class twodanalysis.Packing.PackingDefects(universe, connection_chains=None, lipid_list=None, verbose=False, edges=None, nbins=100, working_lip=None, forcefield='charmm')[source]

Bases: MembProp

packing_defects(layer='top', nbins=None, height=False, periodic=False, edges=None, area=True, count=True)[source]

Compute packing defects based on packmem: https://doi.org/10.1016/j.bpj.2018.06.025

Parameters:
  • layer (str, optional) – working layer (top/bot). Defaults to ‘top’, by default ‘top’

  • nbins (int, optional) – Number of bins of the xy grid, by default None

  • height (bool, optional) – Store height matrix (To study deepness of th packing defects), by default False

  • periodic (bool, optional) – Defines if using periodicity or not. When True, takes into acount periodicity and returns a 2D grid with of the size of the periodic box, by default False

  • edges (list(float)) – List with edges in the shape [xmin,xmax,ymin,ymax], defaults to None

  • area (bool) – If True computes tha area of the packing defects for return

  • count (bool) – If True computes the number of packing defects in the region

Returns:

  • ndarray – If height == Flase: matrix with packing defects

  • ndarray, ndarray – If height === True: matrix with packing defects, matrix with height information

static create_circle_array(grid_size, radius_A, center=None)[source]

Create a small matrix with a inner circle of the size of radius_A

Parameters:
  • grid_size (float) – define the grid size to create the optimun grid (Amstrongs)

  • radius_A (float) – define the radius for the matrix (amstrongs)

  • center (bool, optional) – Bool to set the center of the circle, by default None

Returns:

array with a circle of ones

Return type:

ndarray

static add_small_matrix(big_matrix, small_matrix, center_i, center_j)[source]

Add smmall matrix to a big matrix

Parameters:
  • big_matrix (ndarray(n,n)) – big matrix where a small matrix will be added

  • small_matrix (ndarray(m,m)) – small matrix to be added

  • center_i (int) – i coordinate

  • center_j (int) – j coordinate

Returns:

big matrix modified

Return type:

ndarray(n,n)

add_defects(matrix, indexes, elements, names, lipid, mat_radii_dict)[source]

Code to easily add defects in the 2d matrix

Parameters:
  • matrix (ndarray(n,n)) – Matrix where the defects are going to be added

  • indexes (ndarray(i,j)) – List of indexes i,j in the matrix where the defects should be added

  • elements (list) – type of element (needed to put the right radious)

  • names (list) – names of the atoms (needed to map hydrophobic and not hydrophobic atoms)

  • lipid (str) – lipid name

  • mat_radii_dict (dict) – dictionary with the radii

Returns:

matrix matrix filled with the defects

Return type:

ndarray

static get_highest(data, min_lenght)[source]

Code to get the highest value given two columns that are to be ordered in a 2D grid :Parameters: * data ((ndarray(:,2))) – Array with two columns (column1: map to a 2D grid, column2: values)

  • min_lenght ((int)) – Size of squares in the 2D grid

Returns:

ndarray( – With the maximun of each grid square

Return type:

,2)

get_indexes(data, bins=10, edges=None, matrix_height=False)[source]

given data in 2D, the code returns the indexes to locate the data in the 2D grid defined by edges and bins

Parameters:
  • data (ndarray(n,2 o 3)) – Data in 2D fashion, (3 columns if height = True)

  • bins (int, optional) – number of bins of the grid, by default 10

  • edges (list, optional) – Edges in the following way [xmin,xmax,ymin,ymax], by default None

  • matrix_height (bool, optional) – returns the height matrix (matrix with only the lipids closer to water), by default False

Returns:

  • tuple – tuple with the indexes

  • tuple, ndarray(bins,bins) – tuple with indexes and 2D data of the highest point

packing_defects_stats(nbins=180, layer='top', edges=None, periodic=False, start=0, final=-1, step=1, area_size=True)[source]
Run packing defects from start to final and stores data

about area of defects, total area, number of defects, and size of defects

Parameters:
  • nbins (int, optional) – number of bins to consider, by default 180

  • layer (str, optional) – layer to consider, can be top, bot, by default “top”

  • edges (list(float), optional) – Edges in the shape [xmin,xmax,ymin,ymax], by default None

  • periodic (bool, optional) – Consider or not periodicity, by default False

  • start (int, optional) – stat frame, by default 0

  • final (int, optional) – final frame, by default -1

  • step (int, optional) – frames to skip, by default 1

  • area_size (bool, optional) – If true return the areas of the different defects, by default True

Returns:

pandas dataframe with the area information of packing defects over time and informationabout the size of the packing defects

Return type:

pd.DataFrame, np.array

class twodanalysis.BioPolymer2D.BioPolymer2D(obj, surf_selection=None, biopol_selection=None, start=None, step=None, end=None, by_frames=True, surf_axis='z')[source]

Bases: object

Class Initialization.

Parameters:
  • obj (AtomGroup or Universe) – Selection to initialize the class. If initialized with a Universe it will take the whole Universe as AtomGroup. The MDAnalysis Universe and AtomGroup will be accesible to with the self.universe and self.atom_group class attributes.

  • surf_selection (str, optional) – String selection in MDAnalysis format to define the surface (recomended). If surf_selection is given, surf_pos attribute will save the mean position of the surface over the time. This will particularly important for setting the zlim variable some of the analysis require. By default None

  • biopol_selection (str, optional) – String selection in MDAnalysis format to define the biopolymer as a selection of a Universe or AtomGroup. If None, all the AtomGroup or Universe from obj is used. Default in None.

  • start (float, optional) – Starting time or frame from the trajectory to initialize the object. If by_frames=True, it will be considered as the frame number of the trajectory to start the object. If by_frames=False, it will set the time in ns. If None, start is frame 0 of the trajectory. By default None

  • step (float, optional) – Time or frame steps from the trajectory to initialize the object. If by_frames=True, it will be considered as the step of frames of the trajectory to consider. If by_frames=False, it will set the time steps in ns. If None, all the frames of the trajectory are considered. By default None

  • end (float, optional) – Final time or frame from the trajectory to initialize the object. If by_frames=True, it will be considered as the final frame number of the trajectory to consider. If by_frames=False, it will set the time in ns. If None, end is frame 0 of the trajectory. By default None

  • by_frame (bool, optional) – Whether or not to consider ‘start’, ‘step’ and ‘end’ inputs as frame values. If False, they are consider as time values in ns.

  • surf_axis (str, optional) – Set in which distance is the surface. By default ‘z’

Raises:

TypeError – Error raised if class is not initialized with a Universe or AtomGroup

INFO()[source]

Prints general information of the Universe and/or Atomgroup

getPositions(pos_type='COM', surf_is_zero=True, inplace=True, select=None, getselection=False)[source]

Computes positions of selection from self.startT to self.endT with self.stepT steps of times. By default, these parameters are set to compute over the whole trajectory.

Parameters:
  • pos_type (str, optional) – Computes the positions of “all” atoms of the object or the “COM” (center of mass) of residues, by default ‘COM’.

  • surf_is_zero (bool, optional) – Whether to set position coordinate of the BioPolymer respect to the surface, computing \(z_{\textrm{biopol}}^i-z_{\textrm{surf}}\) for each residue or atom. By default is True.

  • inplace (bool, optional) – If True, position values are assigned to the self.pos attribute and None is returned. If False, positions are returned, by default True

  • select (None or str, optional) – If None, all atoms in the Atom group are computed. Otherwise, it is a string selection analogue to MDAnalysis format. Selection must be a set of atoms of the Atom group. Defaults to None. Whether or not to return the selected MDAnalysis AtomGroup as output.

  • getselection – Whether or not to return the positions and the AtomGroup of residues.

Returns:

None if inplace=True, numpy array if inplace=False with the positions of the center of mass of residues (if pos_type=”COM”) or positions of all atoms (pos_type=”all”)

Return type:

None or np.ndarray

getCOMs(inplace=True, select=None)[source]

Computes positions of selection from self.startT to self.endT with self.stepT steps of time. By default, these parameters are set to compute over the whole trajectory.

Parameters:
  • inplace (bool, optional) – If True, position values are assigned to the self.com attribute and None is returned. If False, center of mass at each frame are returned. By default True

  • select (None or str, optional) – If None, all atoms in the Atom group are computed. Otherwise, it is a string selection analogue to MDAnalysis format. Selection must be a set of atoms of the Atom group. By default None

Returns:

None if inplace=True, numpy array if inplace=False with the center of mass of the AtomGroup.

Return type:

None or np.ndarray

static FilterMinFrames(pos, zlim, Nframes, control_plots=False, getNframes=False)[source]

Selects a set of Nframes in which the AtomGroup is closer to the surface and bellow a zlim threshold distance to the surface.

Parameters:
  • pos (list or np.ndarray (TotalFrames,Nresidues or Natoms,4 <t,x,y,z>)) – Positions over time to be filtered.

  • zlim (float) – Distance (in angstroms) threshold limit in which the AtomGroup is considered adsorped to the surface.

  • Nframes (int) – Nframes closest to the surface within the frames where the AtomGroup is < zlim.

  • control_plots (bool, optional) – If control plots are to be shown, by default False

  • getNframes (bool, optional) – If True, returns the number of frames selected, by default False

Raises:

ValueError – Error raised if Nframes is bigger than the number of frames within the zlim angs threshold from the surface.

Returns:

Filtered positions (Nframes,Nresidues or Natoms,4 <t,x,y,z>)

Return type:

np.ndarray

PolarAnalysis(select_res, Nframes, zlim=14, max_hist=None, sort=None, ax=None, plot=False, colors=['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'], control_plots=False, Nbins=1000, resolution=5)[source]

Makes a Polar Histogram of the positions of the center of mass of select_res residues considering Nframes closest to the surface within the < zlim threshold. self.pos attribute is used to compute the center of mass of the AtomGroup, which will be the referential center of the histograms. The colors of the histogram are ordered according to sort parameter.

Parameters:
  • select_res (str) – MDAnalysis string selection of the residues to which compute the histograms.

  • Nframes (int) – Number of frames closest to the surface to consider that are at zlim distance from self.surf_pos. self.surf_pos must not be None. If Nframes > the total number of frames in tha zlim adsorption threshold,the total of frames in the thresh are considered.

  • zlim (float, optional) – Distance (in angstroms) threshold limit in which the AtomGroup is considered adsorped to the surface, by default 14

  • max_hist (None or float, optional) – Value to normalize the histograms. If None, highest histogram value is used to normalize the histograms, by default None

  • sort (str, list, ndarray or None, optional) – How to sort the histograms in the legend and the coloring. If “max”, histograms will be ploted descending from the residue with highest peak in its histogram to the flattest peak. If sort is a list or ndarray, sort is the index positions of the residues to which reorder the histograms. If None, they well be plotted by MDAnalysis default sort (ascending Resid values)., by default None

  • ax (matplotlib.axes.Axes, optional) – Set plot on a predefined Axis. If None, function defines if own axis internally. By default None

  • plot (bool, optional) – Show the polar plot (True) or only return the data (False), by default False

  • colors (list, optional) – List of colors to use in the polar plot. If None, default matplotlib colors are used. By default [‘C%s’%(c) for c in range(10)]

  • control_plots (bool, optional) – Show control plots of the different steps of the polar analysis calculation., by default False

  • Nbins (int, optional) – How many bins to use in the histograms., by default 1000

  • resolution (float, optional) – One the position vectors of each residue are normalized, resolution is the value too which the normalized positions are multiplied. An increase in this value will make higher peaks in the histograms since position vector are further away. Reducing this value represents an increase of resolution of the histogram. By default 5

Raises:

KeyError – Error raised if self.surf_axis is not ‘x’, ‘y’ or ‘z’.

Returns:

Histogram data (Nresidues, 2 <X_bin_values,Y_bin_values>, Nbins), Positions in order in which they were plotted (Nframes,Nresidues or Natoms,4 <t,x,y,z>)

Return type:

list,np.ndarray

computeRG2D(masses, total_mass)[source]

Computes parallel, perpendicular and 3D radius of gyration in 1 frame.

\[R_{\textrm{g}\parallel}= \sqrt{ \frac{1}{m_T}\sum_{i} m_{i}\left[ (x_i-x_{\textrm{CM}})^2+(y_i-y_{\text{CM}})^2\right]}\]
\[R_{\textrm{g}\perp} = \sqrt{\frac{1}{m_T}\sum_{i} m_{i} (z_i-z_{\text{CM}})^2,}\]

where \({\bf R}_{\textrm{CM}}=(x_{\textrm{CM}}\), \(y_{\textrm{CM}}\), \(z_{\textrm{CM}})\) is the position of the center of mass, \(m_{i}\) the mass of each residue and \(m_T\) the total mass of the residues.

Parameters:
  • masses (np.ndarray (Natoms)) – Mass vallues of each atom.

  • total_mass (float, optional) – Sum of these masses

Returns:

3D, perpendicular and parallel radius of gyration values (3, Natoms)

Return type:

np.ndarray

getRgs2D(plot=False)[source]

Computes the radii of gyration over the trajectory using computeRG2D method.

Parameters:

plot (bool, optional) – If True, it plots the raw Rg data values in time, by default False

Returns:

3D, perpendicular and parallel radius of gyration values at each frame (self.endF-self.startF frames,3, Natoms)

Return type:

np.ndarray

RgPerpvsRgsPar(rgs, color, marker='s', plot='both', ax=None, legend=True, show=False, mfc='k', markersize=10, system_label=None)[source]

Generates \(R_{g\perp}\) vs. \(R_{g\parallel}\) plots. Also, returns the \(\langle R_{g\perp}^2 \rangle /\langle R_{g\parallel}^2 \rangle\) ratio

Parameters:
  • rgs (np.ndarray) – Radii of gyration data. It must have Rg data as [Rg 3D, Rg parallel, Rg perpendicular], analogue to getRgs2D functions

  • color (str) – Color used to plot points. Color names use the same of those of Matplotlib package.

  • marker (str, optional) – Marker used to plot. Marker names use the same of those of Matplotlib package. , by default ‘s’

  • plot (str, optional) – Whether to plot only the raw data (plot='data'), only the mean value of the data (plot='mean'), or both (plot='both.')

  • ax (matplotlib.axes.Axes, optional) – Set plot on a predefined Axis. If None, function defines if own axis internally. By default None

  • legend (bool, optional) – Whether or not to make the default legend, by default True

  • show (bool, optional) – If True, matplotlib.pyplot.show() is executed. This is left optional in case further characterization of plot is desired. Also, this enables showing multple data in the same figure. By default False.

  • mfc (str, optional) – Set marker face color. Color options are intrinsic colors used in Matplotlib library.

  • markersize (int, optional) – Size of colors. Uses the same values as intrinsic values of Matplotlib library.

  • system_label (str, optional) – Label to assign to the system in the legend. If None, the system name is used. By default None

Raises:

KeyError – Error raised if plot is different than ‘data’, ‘mean’ or ‘both’. Error raised if legend=True,``system_label`` is None and the system name is not defined.

Returns:

\(\langle R_{g\perp}^2 \rangle /\langle R_{g\parallel}^2 \rangle\)

Return type:

float

static ListPathsInLevel(kde_plot, contour_level, plot_paths=False)[source]

Lists vertices of a path in a contour level of the KDE plot.

Parameters:
  • kde_plot (kde_plot) – Results of seaborn.kde_plot function. Once computed getKDEAnalysis, self.kde stores this input.

  • contour_level (int) – Contour Level in which to enlist paths or vertices.

  • plot_paths (bool, optional) – If True,all the paths of a given contour level are plotted, by default False

getKDEAnalysis(zlim, Nframes, axis=['x', 'y'], inplace=True, ax=None, show=False, control_plots=False)[source]

Computes KDE Contours using seaborn.kde_plot() function and extracts the paths of each contour level. The output of the seaborn.kde_plot() is stored in self.kdeanalysis.kde, and the paths of each contour level is stored in self.kdeanalysis.paths if inplace=True.

Parameters:
  • zlim (float) – zlim of BioPolymer2D.FilterMinFrames(). Only use frames under a zlim threshold, to avoid using frames with desorbed molecule.

  • Nframes (int) – Nframes of BioPolymer2D.FilterMinFrames(). To ensure to have a controled number of frames under zlim threshold.

  • axis (list, optional) – Axes for which to make the KDE plot. Default is x and y axis.

  • inplace (bool, optional) – If True, stores the paths of al contour levels in self.kdeanalysis.paths. Otherwise, it only returns it. By default True

  • ax (matplotlib.axes.Axes, optional) – Set plot on a predefined Axis. If None, function defines if own axis internally. By default None

  • show (bool, optional) – If True, matplotlib.pyplot.show() is executed. This is left optional in case further characterization of plot is desired. Also, this enables showing multple data in the same figure. By default False.

  • control_plots (bool, optional) – Make control plots, by default False

Returns:

List of all paths in all the contour levels.

Return type:

list

static getAreas(paths, contour_lvl, getTotal=False)[source]

Computes the area of each path a given contour level. Negative values of area are holes in the contour level. If getTotal=True, computes the area of the whole contour level.

Parameters:
  • paths (list) – Paths of all contour levels.

  • contour_lvl (int) – Contour level to compute the area.

  • getTotal (bool, optional) – If False, gives the area of each path of the contour level. If getTotal=True, sums up the contribution of each path in the contour level returning the area of the whole contour level. By default False

Returns:

A list with the area of each path in the contour level, or the total area of the contour level (if getTotal=True)

Return type:

list or float

KDEAnalysisSelection(select_res, Nframes, zlim=15, ax=None, show=False, legend=False, plot_COM=True, getNframes=False, def_colors=['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'])[source]

KDE Contours for a set of selected residues. This computes the paths of all the contour levels of each residue.

Parameters:
  • select_res (str) – MDAnalaysis-like selection of residues to compute their KDE Contour paths

  • Nframes (int, optional) – Number of frames to use within \(mean(z_{select\_res})\) < zlim. This fills value of self.FilterMinFrames.

  • zlim (float, optional) – Height limit to consider as adsorted frames. This fills value of self.FilterMinFrames, by default 15

  • ax (matplotlib.axes.Axes, optional) – Set plot on a predefined Axis. If None, function defines if own axis internally. By default None

  • show (bool, optional) – Where or not to show plot. Convinient to use False if you want modify the default plot, by default False

  • legend (bool, optional) – Whether or not to make the default legend, by default False

  • plot_COM (bool, optional) – Whether or not to plot the center of mass of select_res. Particularly relevant if comparing results with PolarAnalysis method, since this will be the center of the polar histograms if select_res are the same in both analysis. By default True

  • getNframes (bool, optional) – If True, returns the number of frames selected, by default False

  • def_colors (list, optional) – List of colors to use for each residue. By default [“C%i”%(i) for i in range(10)], which are the default colors of Matplotlib.

Returns:

Returns a list with the contour levels paths of each selected residue, and selected AtomGroup. The list of contour levels paths and the reisudes in the AtomGroup are ordered consistently.

Return type:

(list(list)), AtomGroup

getHbonds(selection1, selection2, update_selections=True, trj_plot=False, inplace=True)[source]

Computes H-bonds between to selection1 and selection2 of the trajectory using MDAnalysis.analysis.hydrogenbonds.HydrogenBondAnalysis.

Parameters:
  • selection1 (str) – First selection to which compute H-bonds

  • selection2 (str) – Second selection to which compute H-bonds

  • update_selections (bool, optional) – Fills parameter update_selection from MDAnalysis.analysis.hydrogenbonds.HydrogenBondAnalysis. If True, it updates donor and acceptor at each frame. , by default True

  • trj_plot (bool, optional) – True to have a look at the Hbonds over the trajectory. By default False

  • inplace (bool, optional) – If True, it stores results of H-bond run in self.hbonds. by default True

Raises:

SelectionError – Error raised if any of the two selections lack of hydrogens or acceptors.

Returns:

A list with the area of each path in the contour level, or the total area of the contour level (if getTotal=True)

Return type:

MDAnalysis.analysis.base.Results

HbondsPerResidues(sorted=True, unique_res=False)[source]

Computes the number of H-bonds of each residue during the simulation. self.getHbonds(inplace=True) must be computed prior to the use this function.

Parameters:
  • sorted (bool, optional) – If True, returns data sorted by number of H-bonds. By default True

  • unique_res (bool, optional) – Whether or not to consider only one hydrogen bond per residue. Important to consider percentage in which a residue participates in a H-bond. By default False

Returns:

DataFrame showing all the residues with H-bonds and H-bond count

Return type:

pandas.DataFrame

plotHbondsPerResidues(paths_for_contour, max_circle_size=160, colors=['C0', 'C1', 'C2', 'C3', 'C4', 'C5', 'C6', 'C7', 'C8', 'C9'], top=-1, contour_lvls_to_plot=None, contour_colors=None, contour_ls=None, contour_lw=None, contour_alphas=None, filter=None, print_table=True, show=False, ax=None)[source]

Makes a figure showing the center of mass of the residues with H-bonds. Figure shows a contour plot as a reference of position of the whole molecule. Legend of the Figure shows the percentage of time in which there were Hbonds during the simulation of the plotted residues.

Parameters:
  • paths_for_contour (list) – List of paths of all the contour levels.

  • max_circle_size (int, optional) – Maximum size of the circle representing the residue with most H-bonds. By default 160

  • colors (list, optional) – List of colors to use for each residue. By default [‘C%s’ % i for i in range(10)], which are the default colors of Matplotlib. If the number of residues is greater than 10, the colors are cycled.

  • top (int, optional) – Residues are plotted ranked by residues with most contact to least. This parameters indicates how many residues to plot of these ranked residues, e.g. top=5 wil plot the 5 residues with most Hbonds during the simulations. By default -1, plots all the residues with H-bonds.

  • contour_lvls_to_plot (list, optional) – Contour Levels to show in plot, by default None

  • contour_colors (list, optional) – Colors to use to show the reference contour levels.This list must be the same size than contour_lvls_to_plot parameter. Default None, which all reference contour plots are shown in black.

  • contour_ls (list, optional) – Line style of the contour levels. Default is a solid line.

  • contour_lw (list, optional) – Line width of the contour levels. Default is None.

  • contour_alphas (list, optional) – Transparency of the contour levels. Default is 0.3.

  • filter (str, optional) – Filter out a residue from the plot. By default None

  • print_table (bool, optional) – Whether or not to print the pandas.DataFrame table with the data shown in figure, by default True

  • ax (matplotlib.axes.Axes, optional) – Set plot on a predefined Axis. If None, function defines if own axis internally. By default None

  • show (bool, optional) – Whether or not to show the figure. Convinient to use False if want to do further tunning the plot. By default False

Returns:

Sorted DataFrame from the residues with most contact to the residue with least contacts.

Return type:

pandas.DataFrame

static plotPathsInLevel(paths, contour_lvl, color='k', alpha=0.3, ls='-', lw=None, show=False, ax=None)[source]

Plots the paths of a given contour level.

Parameters:
  • paths (list) – List with all the paths of all the contour levels.

  • contour_lvl (int) – Contour level to plot

  • color (str, optional) – Color to plot the contour level , by default ‘k’, corresponding to a black color.

  • alpha (float, optional) – Sets trasparency. Fills parameter alpha of matplolib.pyplot.plot method by default 0.3

  • ax (matplotlib.axes.Axes, optional) – Set plot on a predefined Axis. If None, function defines if own axis internally. By default None

  • show (bool, optional) – Where to show or not the plot yet with matplolib.pyplot.plot, by default False