### Set up Local Development Environment Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/CONTRIBUTING.rst Install the project in a virtual environment using `python setup.py develop`. ```bash mkvirtualenv mdvoxelclustering cd mdvoxelclustering/ python setup.py develop ``` -------------------------------- ### Start a New Branch Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/.gitsyncing.txt Initiates a new branch for development by checking out the development branch, pulling the latest changes, and creating a new branch. ```bash git checkout development git pull git branch "New-Branch" ``` -------------------------------- ### Install MDVoxelSegmentation using pip Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst Install the MDVoxelSegmentation package directly from its GitHub repository using pip. This command ensures you get the latest version. ```bash pip install git+https://github.com/marrink-lab/MDVoxelSegmentation ``` -------------------------------- ### Get Lipid Segments from Selection Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.html Retrieves lipid segments for a given selection in the current frame. The selection must follow basic mda selection syntax. ```python def get_segments_from_selection(self, selection): """Returns an array of lipids segments for the given resname in the current frame. The selection should adhere to the basic mda selection syntax.""" selection = self.u.select_atoms(selection) resids = selection.residues.ix segments = [container.get_segment_from_resid(resid) for resid in resids] return np.asarray(segments, dtype=int) ``` -------------------------------- ### Clone the Repository Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/CONTRIBUTING.rst Clone your forked repository locally to begin development. ```bash $ git clone git@github.com:your_name_here/mdvoxelclustering.git ``` -------------------------------- ### Run Tests and Checks Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/CONTRIBUTING.rst Ensure your changes pass flake8 and tests, including cross-version compatibility with tox. ```bash flake8 mdvoxelclustering tests python setup.py test tox ``` -------------------------------- ### Loading Molecular Dynamics Universe Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Initializes an MDAnalysis Universe object with the provided topology and trajectory files. Note: Ignore UserWarnings related to mass guessing for coarse-grained beads. ```python u = mda.Universe(gro, xtc) ``` -------------------------------- ### Importing Libraries Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Imports necessary libraries for data manipulation, visualization, and molecular dynamics analysis. ```python import matplotlib.pyplot as plt import numpy as np import MDAnalysis as mda ``` -------------------------------- ### Check MDVoxelSegmentation help Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst Run this command in your terminal to display the help message for the mdvseg command-line tool. This shows available options and usage. ```bash mdvseg -h ``` -------------------------------- ### Visualize VMD Clusters Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst Launches VMD with a specified cluster visualization file. This automatically assigns colors and materials to the first 32 segments for easy selection and visualization. ```bash vmd -e vmd_clusters_visualization.vmd ``` -------------------------------- ### Run a Subset of Tests Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/CONTRIBUTING.rst Execute a specific test module using the `unittest` module. ```python python -m unittest tests.test_mdvoxelclustering ``` -------------------------------- ### Defining File Paths Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Specifies the file paths for the simulation's topology (gro), trajectory (xtc), and segmentation data. ```python gro = '../eq_dry.gro' xtc = '../md_dry.xtc' segmentation_data = '../segmentation_new/clusters.npy' ``` -------------------------------- ### Create a New Branch Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/CONTRIBUTING.rst Create a new branch for your bugfix or feature development. ```bash git checkout -b name-of-your-bugfix-or-feature ``` -------------------------------- ### Initializing Container and Defining Lipids Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Creates an instance of the Container class and defines the target leaflet IDs and residues of interest (cholesterol). ```python # Create our container container = Container(u, segmentation) # We explicitly state our leaflets and lipids of interest leaflet1 = 1 leaflet2 = 2 residues = container.u.select_atoms('resname CHOL').residues ``` -------------------------------- ### Activate and Check Branch Status Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/.gitsyncing.txt Switches to the newly created branch and displays its current status. ```bash git checkout "New-Branch" git status ``` -------------------------------- ### Commit and Push Changes Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/CONTRIBUTING.rst Commit your local changes and push the branch to your GitHub fork. ```bash git add . git commit -m "Your detailed description of your changes." git push origin name-of-your-bugfix-or-feature ``` -------------------------------- ### Initialize and Assign Segments Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Initializes segment masks and assigns segment IDs to frames. This sets up the base data for flip-flop analysis. ```python leaflet_mask1 = segments_per_frame==leaflet1 leaflet_mask2 = segments_per_frame==leaflet2 segments_per_frame[:] = 0 segments_per_frame[leaflet_mask1] = 1 segments_per_frame[leaflet_mask2] = 2 print(segments_per_frame) ``` -------------------------------- ### Perform Basic Segmentation Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst Perform default segmentation on GRO and XTC files for coarse-grain Martini systems. The output is saved to clusters.npy. Adjusting force segmentation (-fs) and recursion depth (-rd) impacts performance. ```bash mdvseg -f path_to_your.gro -x path_to_your.xtc ``` -------------------------------- ### Preparing Segment Tracking Array Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Initializes a NumPy array to store the segment assignments for each lipid residue across all trajectory frames. ```python # Preparing our segment per resid array segments_per_frame = np.zeros((len(container.u.trajectory), len(residues))) segments_per_frame.shape ``` -------------------------------- ### Atomistic Segmentation with CHARMM Force Field Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst Configure selections for atomistic segmentation of DOPE lipids using the CHARMM force field. This involves defining headgroups, linkers, and tails. Run mdvseg with specified selections and disable hyper-resolution for atomistic data. ```bash $ vi selections.inp ## Create an empty `selections.inp` and add the following lines, the selection ## syntax should always be one line and directly follow its header description. # It is not bad to include the linkers in the headgroups as well, but this is often # not important. [charmm_heads] (name N P C12 C11 O11 O12 O13 O14) [charmm_linkers] (name C1 C2 O21 C21 C3 O31 C31) # Not adding the first carbons of the tail can improve performance, but again, # this is usually not important. [charmm_tails] (name C22 C23 C24 C25 C26 C27 C28 C29 C210 C211 C212 C213 C214 C215 C216 C217 C218 C32 C33 C34 C35 C36 C37 C38 C39 C310 C311 C312 C313 C314 C315 C316 C317 C318) ## Run the mdvseg, hyper resolution can be turned off for there are more than ## enough particles due to the atomistic resolution! $ mdvseg -f your.gro -x your.xtc -hg charmm_heads -lg charmm_linkers -tg charmm_tails -hres 0 ``` -------------------------------- ### Plot Flip-Flop Results Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.html Plots the calculated sums of absolute flips per frame to visualize the flip-flop activity over the simulation trajectory. ```python import matplotlib.pyplot as plt plt.plot(sums) plt.show() ``` -------------------------------- ### Add New Branch Online Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/.gitsyncing.txt Pushes the newly created local branch to the remote repository and sets it as the upstream branch. ```bash git push --set-upstream origin "New-Branch" ``` -------------------------------- ### Citation for MDVoxelSegmentation Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst This is the citation information for the MDVoxelSegmentation article. It should be used when referencing the software in publications. ```bibtex @article{Bruininks2021, doi = {10.1021/acs.jctc.1c00446}, url = {https://doi.org/10.1021/acs.jctc.1c00446}, year = {2021}, month = oct, publisher = {American Chemical Society ({ACS})}, volume = {17}, number = {12}, pages = {7873--7885}, author = {Bart M. H. Bruininks and Albert S. Thie and Paulo C. T. Souza and Tsjerk A. Wassenaar and Shirin Faraji and Siewert J. Marrink}, title = {Sequential Voxel-Based Leaflet Segmentation of Complex Lipid Morphologies}, journal = {Journal of Chemical Theory and Computation} } ``` -------------------------------- ### Setting Active Frame Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Sets the current trajectory frame to the first frame (index 0) for initial analysis. ```python # Set the active frame to frame 0 container.u.trajectory[0] ``` -------------------------------- ### Loading Segmentation Data Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Loads the pre-computed segmentation data from a NumPy file. ```python segmentation = np.load(segmentation_data) ``` -------------------------------- ### Plot Up and Down Flips Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Plots the counts of upward and downward flips separately over time, allowing for a detailed analysis of flip-flop dynamics. ```python plt.plot(ups_and_downs['ups']) plt.plot(ups_and_downs['downs']) plt.show() ``` -------------------------------- ### Fetch Segment ID from Residue or Selection Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst Provides a Python class 'Container' to interact with MDAnalysis universes and segmentation data. It allows fetching segment IDs by residue index or by MDAnalysis selection syntax. ```python class Container(): """A simple container class for our universe and segmentation data.""" def __init__(self, universe, segmentation): self.u = universe self.segmentation = segmentation def get_segment_from_resid(self, resid): """Returns the residue segment id in the current frame.""" residue_index = self.u.residues[resid].atoms[0].ix current_frame = self.u.trajectory.frame residue_segment = self.segmentation[current_frame, residue_index] return residue_segment def get_segments_from_selection(self, selection): """Returns an array of lipid segments for the given selection in the current frame. The selection should adhere to the basic mda selection syntax.""" selection = self.u.select_atoms(selection) resids = selection.residues.ix segments = [container.get_segment_from_resid(resid) for resid in resids] return np.asarray(segments, dtype=int) # File paths gro = 'your.gro' xtc = 'your.xtc' segmentation_data = 'clusters.npy' # Creating universe and loading segmentation u = mda.Universe(gro, xtc) segmentation = np.load(segmentation_data) # Create our container container = Container(u, segmentation) # Segment from resid resid1_segmentID = container.get_segment_from_resid(1) # Segment from selection all_cholesterol_segmentsIDs = container.get_segments_from_selection('resname CHOL') ``` -------------------------------- ### Resync and Merge Changes Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/.gitsyncing.txt Pulls the latest changes from the remote repository to synchronize the local branch. Merging should be handled via GUI or terminal. ```bash git pull ``` -------------------------------- ### Handle Unassigned Segments Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Iterates through simulation frames to fill in unassigned segments (value 0) with the segment ID from the previous frame. This ensures continuity in segment assignments. ```python # Setting all values which are not relevant to their previous segment. # This is for loop and probably we can do this better, but # for now it is at least clear what we are doing. for idx, frame in enumerate(segments_per_frame): if idx == 0: continue else: # Find the indices of all the residues which # are not asigne to 0. bad_resids = np.where(frame == 0)[0] if bad_resids.size: print('There is a bad one!') # Set the value of a non set segment to the previous # value. previous_frame = segments_per_frame[idx-1] frame[list(bad_resids)] = previous_frame[bad_resids] ``` -------------------------------- ### Populating Segment Data Across Frames Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Iterates through each frame of the trajectory, extracts segment assignments for cholesterol lipids using the Container's method, and prints progress. ```python # Obtain the resid segment for each frame for idx, frame in enumerate(container.u.trajectory): segments_per_frame[idx] = container.get_segments_from_selection('resname CHOL') print(f'\rWorking on frame {idx+1}/{segments_per_frame.shape[0]}. ', end='') ``` -------------------------------- ### Verify Segment Assignment Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Prints segment assignments for specific frame and residue indices to verify the correctness of the segment assignment process. ```python # These values should now be the same. print(segments_per_frame[ 9, [11, 12]]) print(segments_per_frame[10, [11, 12]]) ``` -------------------------------- ### Manually Control Plotting Script Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst After running the basic segmentation, a plotting script is generated. You can manually alter this script and re-run it to customize the segmentation graph output. ```bash python plotting.py # alter this and rerun ``` -------------------------------- ### Displaying Segment Data Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Prints the entire NumPy array containing segment assignments for each lipid across all frames. ```python print(segments_per_frame) ``` -------------------------------- ### Commit Changes to Current Branch Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/.gitsyncing.txt Stages all changes, checks their status, and commits them with a specified message. ```bash git add . git status git commit . -m "write message here" ``` -------------------------------- ### Plot Total Flips Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Plots the sum of absolute flips per frame to visualize the overall activity of segment changes over time. ```python plt.plot(sums) plt.show() ``` -------------------------------- ### Non-Amphipathic Density Segmentation Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst Define a basic non-solvent Martini density selection for segmentation. Run mdvseg without an exclusion group and with forced segmentation turned off. ```bash # Define the density selection $ vi selections.inp [density] (not resname W WF ION) # Basic non-solvent Martini density [none] False # Run mdvseg with the selections.inp without an exclusion group nor forced segmenation. mdvseg -f your.gro -x your.xtc -hg density -tg none -eg none -fs 0 ``` -------------------------------- ### Calculate Frame Differences for Flips Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Calculates the difference between consecutive frames to identify segment flips. A difference of 1 indicates an upward flip, and -1 indicates a downward flip. ```python # Calculating the flips by differentiating flips = segments_per_frame[1:] - segments_per_frame[:-1] ``` -------------------------------- ### Process Lipid Flip Data Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.html Calculates the number of 'ups' (positive flips) and 'downs' (negative flips) from a given dataset of flips. This is useful for quantifying directional changes in lipid movement. ```python ups_and_downs = dict() ups_and_downs['ups'] = [] ups_and_downs['downs'] = [] for row in flips: ups_and_downs['ups'].append(len(np.where(row == 1)[0])) ups_and_downs['downs'].append(-len(np.where(row == -1)[0])) ``` -------------------------------- ### Addressing Irrelevant Assignments Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Explains the strategy to handle irrelevant segment assignments by replacing target values, ensuring that -1 and 1 specifically denote flip events. ```python # To solve the problem of irrelevant assignment we replace out targets, # by doing so we make sure that a value of -1 and 1 reflect a flip. ``` -------------------------------- ### Container Class for MD Data Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb A helper class to encapsulate the MDAnalysis Universe and segmentation data, providing methods to access segment information for residues and selections. ```python class Container(): """A simple container class for our universe and segmentation data.""" def __init__(self, universe, segmentation): self.u = universe self.segmentation = segmentation def get_segment_from_resid(self, resid): """Returns the residue segment id in the current frame.""" residue_index = self.u.residues[resid].atoms[0].ix current_frame = self.u.trajectory.frame residue_segment = self.segmentation[current_frame, residue_index] return residue_segment def get_segments_from_selection(self, selection): """Returns an array of lipids segments for the given resname in the current frame. The selection should adhere to the basic mda selection syntax.""" selection = self.u.select_atoms(selection) resids = selection.residues.ix segments = [container.get_segment_from_resid(resid) for resid in resids] return np.asarray(segments, dtype=int) ``` -------------------------------- ### Close Local Branch Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/.gitsyncing.txt Switches back to the development branch and deletes the local feature branch. ```bash git checkout development git branch -d "New-Branch" ``` -------------------------------- ### Count Up and Down Flips Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Counts the number of upward (value 1) and downward (value -1) flips in each frame. This provides a directional breakdown of segment changes. ```python # Be careful, up and down is relative and this should be checked! ups_and_downs = dict() ups_and_downs['ups'] = [] ups_and_downs['downs'] = [] for row in flips: ups_and_downs['ups'].append(len(np.where(row == 1)[0])) ups_and_downs['downs'].append(-len(np.where(row == -1)[0])) ``` -------------------------------- ### Push Intermediate Changes Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/.gitsyncing.txt Pushes the committed changes from the local branch to the remote repository. ```bash git push ``` -------------------------------- ### Define Data Container Class Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.html A helper class to encapsulate the MDAnalysis Universe and segmentation data. It provides methods for accessing residue information within the current trajectory frame. ```python class Container(): """A simple container class for our universe and segmentation data.""" def __init__(self, universe, segmentation): self.u = universe self.segmentation = segmentation def get_segment_from_resid(self, resid): """Returns the residue segment id in the current frame.""" residue_index = self.u.residues[resid].atoms[0].ix current_frame = self.u.trajectory.frame ``` -------------------------------- ### Plot Segment Count Over Time Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/README.rst Loads segmentation data from 'clusters.npy' and plots the number of unique segments per frame using NumPy and Matplotlib. The plot is saved as 'amount_of_segments_over_time.png'. ```python ## Importing numpy and matplotlib. import numpy as np import matplotlib.pyplot as plt ## Loading the segmentation data. segments_over_time = np.load('clusters.npy') ## Calculating the amount of segments in each frame. # Make an empty array which has one int32 for every frame. segments_per_frame = np.zeros(segments_over_time.shape[0], dtype='int32') # Fill the array with the amount of non-zero segments in each frame. segments_per_frame[:] = [len(np.unique(frame)) - 1 for frame in segments_over_time] ## Plotting the results. # Making an empty plot. fig, ax = plt.subplots() # Adding required data to plot. ax.plot(segments_per_frame) # Set ticks to a sensible regime. start, end = [round(limit) for limit in ax.get_ylim()] ax.yaxis.set_ticks(np.arange(start, end + 1, 1)) # Add labels to axes. ax.set_xlabel('Frame count') ax.set_ylabel('Number of segments') # Save the plot. fig.savefig('amount_of_segments_over_time.png', dpi=300) # Usually people don't like it if you pop windows, however # if you would like to automatically show the result uncomment # the following line. #fig.show() ``` -------------------------------- ### Sum Absolute Flips per Frame Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Calculates the sum of absolute differences for each frame, representing the total number of segment changes in that frame. ```python sums = [np.sum(np.abs(frame)) for frame in flips] ``` -------------------------------- ### Normalize Leaflet Assignments Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.html Replaces segment assignments to normalize them, ensuring that values 1 and 2 represent the target leaflets. All other values are considered irrelevant for flip-flop detection. ```python # To solve the problem of irrelevant assignment we replace out targets, # by doing so we make sure that a value of -1 and 1 reflect a flip. # All other values are not relevant. leaflet_mask1 = segments_per_frame==leaflet1 leaflet_mask2 = segments_per_frame==leaflet2 segments_per_frame[:] = 0 segments_per_frame[leaflet_mask1] = 1 segments_per_frame[leaflet_mask2] = 2 print(segments_per_frame) ``` -------------------------------- ### Modifying Segment Data for Testing Source: https://github.com/marrink-lab/mdvoxelsegmentation/blob/development/src/mdvoxelsegmentation/templates/lipid_flip-flop.ipynb Introduces specific modifications to the segment data array for testing purposes, assigning invalid segment IDs. ```python # Create two faulty ones just for testing. segments_per_frame[10, 12] = 0 segments_per_frame[10, 12] = 15 segments_per_frame[10, [12, 13]] ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.