Skip to content

Commit

Permalink
MERGE: upstream/black_pyproject_toml
Browse files Browse the repository at this point in the history
  • Loading branch information
kannandeepti committed Jan 9, 2023
2 parents 83438bd + 0541fa2 commit 7c5cbdf
Show file tree
Hide file tree
Showing 42 changed files with 837 additions and 82,270 deletions.
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length=120
ignore: E302, W503, W504, E402, E731, F401, E203
10 changes: 10 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Description

_Describe what this PR is for_


## PR Checklist

- [] apply "black" to the whole codebase (`black .`)
- [] apply isort to the codebase (`isort .`)
- [] fun `flake8` and try to resolve all the issues (work in progress!)
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@

# -- Path setup --------------------------------------------------------------

import sys
import os
import re
import shlex
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
2 changes: 1 addition & 1 deletion docs/olddocs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down
41 changes: 19 additions & 22 deletions examples/customIntegrators/activeBD.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,30 @@
Polymer simulations with ActiveBrownianIntegrator
-------------------------------------------------
This is a sample python script to run a polychrom simulation with the `ActiveBrownianIntegrator' custom integrator in polychrom.contrib.integrators. This integrator is used to simulate a polymer where each mononmer has a different effective temperature and thus a different diffusion coefficient :math:`D_i = k_B T_i / \xi`. Here, we consider an example where there are just two types of monomers, active (A) and inactive (B), where :math:`D_A > D_B` and the user chooses the ratio :math:`D_A / D_B`.
This is a sample python script to run a polychrom simulation with the `ActiveBrownianIntegrator' custom integrator in
polychrom.contrib.integrators. This integrator is used to simulate a polymer where each mononmer has a different
effective temperature and thus a different diffusion coefficient :math:`D_i = k_B T_i / \xi`. Here, we consider an
example where there are just two types of monomers, active (A) and inactive (B), where :math:`D_A > D_B` and the user
chooses the ratio :math:`D_A / D_B`.
Run this script using
>>> python activeBD.py [gpuid] [activity_ratio]
"""

import os
import sys
import time
from pathlib import Path

import numpy as np
import os, sys
import openmm
from simtk import unit

import polychrom
from polychrom import simulation, starting_conformations, forces, forcekits
from polychrom import forcekits, forces, simulation, starting_conformations
from polychrom.contrib.integrators import ActiveBrownianIntegrator
import openmm
from polychrom.hdf5_format import HDF5Reporter
from simtk import unit
from pathlib import Path

N = 1000 # 1000 monomers
ids = np.ones(N) # aray of 1s and 0s assigning type A and type B comonomers
Expand All @@ -27,9 +34,7 @@
ids[int(N / 2) :] = 0


def run_monomer_diffusion(
gpuid, N, ids, activity_ratio, timestep=170, nblocks=10, blocksize=100
):
def run_monomer_diffusion(gpuid, N, ids, activity_ratio, timestep=170, nblocks=10, blocksize=100):
"""Run a single simulation on a GPU of a hetero-polymer with A monomers and B monomers. A monomers
have a larger diffusion coefficient than B monomers, with an activity ratio of D_A / D_B.
Expand All @@ -53,12 +58,8 @@ def run_monomer_diffusion(
"""
if len(ids) != N:
raise ValueError(
"The array of monomer identities must have length equal to the total number of monomers."
)
D = np.ones(
(N, 3)
) # Dx, Dy, Dz --> we assume the diffusion coefficient in each spatial dimension is the same
raise ValueError("The array of monomer identities must have length equal to the total number of monomers.")
D = np.ones((N, 3)) # Dx, Dy, Dz --> we assume the diffusion coefficient in each spatial dimension is the same
# by default set the average diffusion coefficient to be 1 kT/friction
# let D_A = 1 + Ddiff and D_B = 1 - Ddiff such that D_A / D_B is the given activity_ratio
Ddiff = (activity_ratio - 1) / (activity_ratio + 1)
Expand All @@ -79,9 +80,7 @@ def run_monomer_diffusion(
particleD = unit.Quantity(D, kT / friction)
integrator = ActiveBrownianIntegrator(timestep, collision_rate, particleD)
gpuid = f"{gpuid}"
reporter = HDF5Reporter(
folder="active_inactive", max_data_length=100, overwrite=True
)
reporter = HDF5Reporter(folder="active_inactive", max_data_length=100, overwrite=True)
sim = simulation.Simulation(
platform="CUDA",
# for custom integrators, feed a tuple with the integrator class reference and a string specifying type,
Expand All @@ -99,9 +98,7 @@ def run_monomer_diffusion(

polymer = starting_conformations.grow_cubic(N, int(np.ceil(r)))
sim.set_data(polymer, center=True) # loads a polymer, puts a center of mass at zero
sim.set_velocities(
v=np.zeros((N, 3))
) # initializes velocities of all monomers to zero (no inertia)
sim.set_velocities(v=np.zeros((N, 3))) # initializes velocities of all monomers to zero (no inertia)
sim.add_force(forces.spherical_confinement(sim, density=density, k=5.0))
sim.add_force(
forcekits.polymer_chains(
Expand All @@ -117,7 +114,7 @@ def run_monomer_diffusion(
nonbonded_force_func=forces.polynomial_repulsive,
nonbonded_force_kwargs={
"trunc": 3.0, # this will let chains cross sometimes
#'trunc':10.0, # this will resolve chain crossings and will not let chain cross anymore
# 'trunc':10.0, # this will resolve chain crossings and will not let chain cross anymore
},
except_bonds=True,
)
Expand Down
43 changes: 26 additions & 17 deletions examples/customIntegrators/corr_noise.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,39 @@
Polymer simulations with CorrelatedNoiseIntegrator
--------------------------------------------------
This is a sample python script to run a polychrom simulation with the `CorrelatedNoiseIntegrator' custom integrator in polychrom.contrib.integrators. This integrator is used to simulate a polymer where the Brownian forces acting on distinct monomers could be correlated in direction. In addition, as in `ActiveBrownianIntegrator`, each monomer can have a different diffusion coefficient :math:`D_i = k_B T_i / \xi`.
To define the correlations, we define a set of k attributes that specify the monomer's identity, such as charge, methylation status, etc. For each attribute, all monomers are assigned type 1, type -1, or type 0. The integrator defines a procedure by which type 1 monomers are correlated with one another with correlation coefficient :math:`\rho`, type -1 monomers are correlated with one another with coefficient :math:`\rho`, but type 1 and type -1 monomers are anticorrelated with coefficient :math:`-\rho`. Type 0 monomers do not experience correlated fluctuations.
Here, we consider a simple example with just 1 feature (say, "charge"), and set all monomer diffusion coefficients to be the same. Thus, all same-charge monomers will be correlated with correlation coefficient 0.5 and opposing charge monomers are anticorrelated with coefficient -0.5. To visualize the Pearson correlation matrix of the N-dimensional Gaussian noise that drives the polymer, use the `compute_Pearson_correlation_matrix()` function.
This is a sample python script to run a polychrom simulation with the `CorrelatedNoiseIntegrator' custom integrator
in polychrom.contrib.integrators. This integrator is used to simulate a polymer where the Brownian forces acting on
distinct monomers could be correlated in direction. In addition, as in `ActiveBrownianIntegrator`, each monomer can
have a different diffusion coefficient :math:`D_i = k_B T_i / \xi`.
To define the correlations, we define a set of k attributes that specify the monomer's identity, such as charge,
methylation status, etc. For each attribute, all monomers are assigned type 1, type -1, or type 0. The integrator
defines a procedure by which type 1 monomers are correlated with one another with correlation coefficient
:math:`\rho`, type -1 monomers are correlated with one another with coefficient :math:`\rho`, but type 1 and type -1
monomers are anticorrelated with coefficient :math:`-\rho`. Type 0 monomers do not experience correlated fluctuations.
Here, we consider a simple example with just 1 feature (say, "charge"), and set all monomer diffusion coefficients to
be the same. Thus, all same-charge monomers will be correlated with correlation coefficient 0.5 and opposing charge
monomers are anticorrelated with coefficient -0.5. To visualize the Pearson correlation matrix of the N-dimensional
Gaussian noise that drives the polymer, use the `compute_Pearson_correlation_matrix()` function.
Run this script using
>>> python corr_noise.py [gpuid]
"""
import os
import sys
import time
from pathlib import Path

import numpy as np
import os, sys
import openmm
from simtk import unit

import polychrom
from polychrom import simulation, starting_conformations, forces, forcekits
from polychrom import forcekits, forces, simulation, starting_conformations
from polychrom.contrib.integrators import CorrelatedNoiseIntegrator
import openmm
from polychrom.hdf5_format import HDF5Reporter
from simtk import unit
from pathlib import Path

N = 100 # 100 monomers

Expand Down Expand Up @@ -88,16 +101,12 @@ def run_correlated_diffusion(gpuid, N, rhos, timestep=170, nblocks=10, blocksize
"""
if rhos.shape[1] != N:
raise ValueError(
"The array of monomer identities must have length equal to the total number of monomers."
)
raise ValueError("The array of monomer identities must have length equal to the total number of monomers.")
# monomer density in confinement in units of monomers/volume
density = 0.224
r = (3 * N / (4 * 3.141592 * density)) ** (1 / 3)
print(f"Radius of confinement: {r}")
D = np.ones(
(N, 3)
) # Diffusion coefficients of N monomers in x,y,z spatial dimensions
D = np.ones((N, 3)) # Diffusion coefficients of N monomers in x,y,z spatial dimensions
timestep = timestep
# the monomer diffusion coefficient should be in units of kT / friction, where friction = mass*collision_rate
collision_rate = 2.0
Expand Down Expand Up @@ -143,7 +152,7 @@ def run_correlated_diffusion(gpuid, N, rhos, timestep=170, nblocks=10, blocksize
nonbonded_force_func=forces.polynomial_repulsive,
nonbonded_force_kwargs={
"trunc": 3.0, # this will let chains cross sometimes
#'trunc':10.0, # this will resolve chain crossings and will not let chain cross anymore
# 'trunc':10.0, # this will resolve chain crossings and will not let chain cross anymore
},
except_bonds=True,
)
Expand Down
20 changes: 11 additions & 9 deletions examples/example/example.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
"""
This is a sample simulation that does not represent any particular biological system. It is just a showcase
of how create a Simulation object, add forces, and initialize the reporter.
This is a sample simulation that does not represent any particular biological system. It is just a showcase
of how create a Simulation object, add forces, and initialize the reporter.
In this simulation, a simple polymer chain of 10,000 monomers is
In this simulation, a simple polymer chain of 10,000 monomers is simulated.
"""


import os, sys
import polychrom
from polychrom import simulation, starting_conformations, forces, forcekits
import openmm
import os
import sys

import openmm

import polychrom
from polychrom import forcekits, forces, simulation, starting_conformations
from polychrom.hdf5_format import HDF5Reporter

N = 10000
Expand Down Expand Up @@ -40,7 +42,7 @@
chains=[(0, None, False)],
# By default the library assumes you have one polymer chain
# If you want to make it a ring, or more than one chain, use self.setChains
# self.setChains([(0,50,True),(50,None,False)]) will set a 50-monomer ring and a chain from monomer 50 to the end
# self.setChains([(0,50,True),(50,None,False)]) will set a 50-monomer ring and a chain from 50 to the end
bond_force_func=forces.harmonic_bonds,
bond_force_kwargs={
"bondLength": 1.0,
Expand All @@ -55,7 +57,7 @@
nonbonded_force_func=forces.polynomial_repulsive,
nonbonded_force_kwargs={
"trunc": 3.0, # this will let chains cross sometimes
#'trunc':10.0, # this will resolve chain crossings and will not let chain cross anymore
# 'trunc':10.0, # this will resolve chain crossings and will not let chain cross anymore
},
except_bonds=True,
)
Expand Down
7 changes: 5 additions & 2 deletions examples/loopExtrusion/LEF_Dynamics.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
#cython: initializedcheck=True

import numpy as np
cimport numpy as np

cimport numpy as np

import cython
cimport cython

cimport cython


cdef extern from "<stdlib.h>":
Expand Down
Loading

0 comments on commit 7c5cbdf

Please sign in to comment.