-
Notifications
You must be signed in to change notification settings - Fork 10
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
draft: add a hydrogel builder #103
Open
1234somesh
wants to merge
14
commits into
pyMBE-dev:main
Choose a base branch
from
1234somesh:hydrogel-feature-branch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+831
−117
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
62bca14
hydrogel feature in pyMBE.py
1234somesh 20f953b
hydrogels-feature refactored
1234somesh 845c84f
Merge branch 'main' into hydrogel-feature-branch
1234somesh abe3861
removed unused variables
1234somesh e86fdad
Merge remote-tracking branch 'origin/hydrogel-feature-branch' into hy…
1234somesh 76c384f
lattice_builder.py - new testsuite WIP
1234somesh 3e84660
lattice_builder modified
1234somesh d04628e
new testuites for hydrogel builder
1234somesh 97f932a
Fix R installation issue in testsuite.yml
1234somesh 17188f7
removed unused variables in hydrogel_builder.py
1234somesh 23cc690
refactoring hydrogel builder testsuite for code coverage
1234somesh 660451a
refactoring hydrogel builder testsuite for code coverage
1234somesh d9883d8
refactoringhydrogel builder testsuite for code coverage
1234somesh bf635a4
refactoringhydrogel builder testsuite for code coverage
1234somesh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
# | ||
# Copyright (C) 2024 pyMBE-dev team | ||
# | ||
# This file is part of pyMBE. | ||
|
@@ -20,17 +19,16 @@ | |
import itertools | ||
import numpy as np | ||
|
||
#pmb = pyMBE.pymbe_library(seed=42) | ||
|
||
class LatticeBuilder: | ||
""" | ||
Generic lattice builder. | ||
|
||
Args: | ||
lattice(`object`): Data class that represents a lattice, for example a :class:`DiamondLattice`. | ||
strict(`bool`): If set to `True`, the lattice connectivity cannot be altered. | ||
For example, a chain cannot be created between two nodes that are | ||
not explicitly connected according to the definition in `lattice`. | ||
|
||
Attributes: | ||
kwargs_node_labels(`dict`): Keyword arguments passed to the matplotlib | ||
`Axes3D.text() <https://matplotlib.org/stable/api/_as_gen/mpl_toolkits.mplot3d.axes3d.Axes3D.text.html>`_ | ||
|
@@ -46,6 +44,8 @@ class LatticeBuilder: | |
function to draw the simulation box. | ||
""" | ||
|
||
# Remove pmb when integrated to main pyMBE.py file | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remember to clean-up these comments before merging it! |
||
def __init__(self, lattice, strict=True): | ||
self.lattice = lattice | ||
self.strict = strict | ||
|
@@ -58,6 +58,9 @@ def __init__(self, lattice, strict=True): | |
self.kwargs_monomers = {} | ||
self.kwargs_bonds = {} | ||
self.kwargs_box = {} | ||
self.MPC = lattice.MPC | ||
self.BOXL = lattice.BOXL | ||
|
||
|
||
def _get_node_by_label(self, node): | ||
assert node in self.node_labels, f"node '{node}' doesn't exist in a {self.lattice.name} lattice" | ||
|
@@ -93,7 +96,6 @@ def _make_sphere(cls, radius, resolution): | |
def add_default_chains(self, mpc): | ||
""" | ||
Build a default lattice network. Skip node pairs that already have a chain defined. | ||
|
||
Args: | ||
mpc(`int`): Number of monomers per chain. | ||
""" | ||
|
@@ -104,7 +106,6 @@ def add_default_chains(self, mpc): | |
def draw_lattice(self, ax): | ||
""" | ||
Draw the lattice in an `Axes3D <https://matplotlib.org/stable/api/toolkits/mplot3d/axes3d.html>`_ canvas. | ||
|
||
Args: | ||
ax: Axes. | ||
""" | ||
|
@@ -150,8 +151,10 @@ def draw_lattice(self, ax): | |
if self.colormap: | ||
color = self.colormap[node_type] | ||
kwargs_monomers["c"] = color | ||
|
||
node_positions = scatter_data[node_type] | ||
pos = np.array(node_positions) | ||
# plotting nodes and monomers | ||
ax_data = ax.scatter(pos[:,0], pos[:,1], pos[:,2], edgecolor="none", | ||
zorder=2, label=node_type, s=12**2, **kwargs_monomers) | ||
color = ax_data.get_facecolors()[0] | ||
|
@@ -163,7 +166,6 @@ def draw_lattice(self, ax): | |
def draw_simulation_box(self, ax): | ||
""" | ||
Draw the simulation box in an `Axes3D <https://matplotlib.org/stable/api/toolkits/mplot3d/axes3d.html>`_ canvas. | ||
|
||
Args: | ||
ax: Axes. | ||
""" | ||
|
@@ -182,11 +184,9 @@ def draw_simulation_box(self, ax): | |
def get_chain(self, node_start, node_end): | ||
""" | ||
Get a chain between two nodes. | ||
|
||
Args: | ||
node_start(`str`): Start node label, e.g. ``[0 0 0]`` for the node at the origin. | ||
node_end(`str`): End node label, e.g. ``[1 1 1]`` for the first node along the diagonal. | ||
|
||
Returns: | ||
`list`: Sequence of residue labels. | ||
""" | ||
|
@@ -202,10 +202,8 @@ def get_monomer_color(self, label): | |
""" | ||
Get the color corresponding to a monomer label. | ||
Only works if a custom color map was set via :meth:`set_colormap`! | ||
|
||
Args: | ||
label(`str`): Monomer label. | ||
|
||
Returns: | ||
The color. | ||
""" | ||
|
@@ -216,10 +214,8 @@ def get_monomer_color_index(self, label): | |
""" | ||
Get the color wheel index corresponding to a monomer label. | ||
Only works if a custom color map was set via :meth:`set_colormap`! | ||
|
||
Args: | ||
label(`str`): Monomer label. | ||
|
||
Returns: | ||
`int`: The color index. | ||
""" | ||
|
@@ -230,56 +226,24 @@ def get_monomer_color_index(self, label): | |
def get_node(self, node): | ||
""" | ||
Get a node residue label. | ||
|
||
Args: | ||
node(`str`): Node label, e.g. ``[0 0 0]`` for the node at the origin. | ||
|
||
Returns: | ||
`str`: Residue label. | ||
""" | ||
key = self._get_node_by_label(node) | ||
return self.nodes[key] | ||
|
||
def set_chain(self, node_start, node_end, sequence): | ||
""" | ||
Set a chain between two nodes. | ||
|
||
Args: | ||
node_start(`str`): Start node label, e.g. ``[0 0 0]`` for the node at the origin. | ||
node_end(`str`): End node label, e.g. ``[1 1 1]`` for the first node along the diagonal. | ||
sequence(`list`): Sequence of residue labels. | ||
""" | ||
assert len(sequence) != 0 and not isinstance(sequence, str) | ||
key, reverse = self._get_node_vector_pair(node_start, node_end) | ||
assert node_start != node_end or sequence == sequence[::-1], \ | ||
(f"chain cannot be defined between '{node_start}' and '{node_end}' since it " | ||
"would form a loop with a non-symmetric sequence (under-defined stereocenter)") | ||
if reverse: | ||
sequence = sequence[::-1] | ||
self.chains[key] = sequence | ||
|
||
def set_colormap(self, colormap): | ||
""" | ||
Set a discrete color map. By default, the standard matplotlib color wheel will be used. | ||
|
||
Args: | ||
colormap(`dict`): Discrete color wheel that maps monomer labels to colors. | ||
""" | ||
assert isinstance(colormap, dict) | ||
self.colormap = colormap.copy() | ||
self.colormap_sorted_names = list(self.colormap.keys()) | ||
|
||
def set_node(self, node, residue): | ||
""" | ||
Set a node residue type. | ||
|
||
Args: | ||
node(`str`): Node label, e.g. ``[0 0 0]`` for the node at the origin. | ||
residue(`str`): Node residue label. | ||
""" | ||
key = self._get_node_by_label(node) | ||
self.nodes[key] = residue | ||
|
||
|
||
class DiamondLattice: | ||
""" | ||
|
@@ -294,3 +258,11 @@ class DiamondLattice: | |
(2, 5), (3, 6), (4, 7), (5, 0), | ||
(5, 3), (5, 4), (6, 0), (6, 2), | ||
(6, 4), (7, 0), (7, 2), (7, 3)} | ||
|
||
def __init__(self,MPC,BOND_LENGTH): | ||
if not isinstance(MPC, int) or MPC <= 0: | ||
raise ValueError("MPC must be a non-zero positive integer.") | ||
self.MPC = MPC | ||
self.BOND_LENGTH = BOND_LENGTH | ||
self.BOXL = (self.MPC+1)*self.BOND_LENGTH.magnitude / (np.sqrt(3)*0.25) | ||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please remember to clean-up these comments before merging it!