Molecular Density Fitting Using 3D Gaussian Functions
This project implements a molecular density fitting approach that optimizes the correlation between an experimental density map and a synthetic density map originating from molecular dynamics using 3D Gaussian functions. The algorithm generates a force in the direction that increases the correlation between the simulated and effective maps. It also allows adjusting anisotropically the spread parameter (sigma) in each direction.
- Efficient simulation of density maps using 3D Gaussian functions.
- Optimization of molecular coordinates and sigma parameters to improve fit.
- Calculation of the correlation coefficient to measure fit quality.
- Use of numerical and analytical methods to compute derivatives.
- Implementation optimized with Numba for high performance.
- Python 3.6+
- Numpy
- SciPy
- Numba
Here's a quick example to get started with the Fit
class:
import numpy as np
from openfit import Fit
# Define your parameters: coordinates, sigma, experimental_map, and voxel_size
coordinates = np.array([...]) # Particle coordinates (n, 3)
sigma = np.array([...]) # Standard deviation (n, 3)
density_map = np.array([...]) # Density map
voxel_size = [1, 1, 1] # Voxel size
# Initialize the Fit object
md_fit = Fit(density_map, voxel_size)
# Calculate the derivative of the correlation over the coordinates and sigma
diff = md_fit.dcorr_coef(coordinates, sigma)
# Perform the fitting process just with the coordinates
md_fit.fit(coordinates, sigma)
# Access the optimized coordinates and sigma
optimized_coordinates = md_fit.coordinates
optimized_sigma = md_fit.sigma
import openfit
import numpy as np
# Parse the pdb
scene = openfit.Scene.from_pdb('pdb_file.pdb')
# Corrects missing element names
scene['element'] = scene['name'].str[0]
scene['mass'] = scene['element'].replace({'N': 14, 'C': 12, 'O': 16, 'S': 32})
# Creates an empty voxel array
coords = scene.get_coordinates()
voxel_size = (coords.max() - coords.min()) / 40 # ~40x40x40
Fit = openfit.Fit.from_dimensions(min_coords=coords.min() - 10, max_coords=coords.max() + 10, voxel_size=voxel_size)
# Sets the coordinates
Fit.set_coordinates(coords.values(), sigma=np.ones(coords.shape) * 2, epsilon=scene['mass'].values)
# Saves the density map
Fit.save_mrc('sample_map.mrc')
This class implements V_fit
, a forcefield potential that can be included in an OpenMM molecular dynamics simulation.
The potential is defined in terms of the correlation coefficient (c.c.), which is a function of the experimental and simulated densities at each voxel
The correlation coefficient (c.c.) is defined as:
where
with the Gaussian function for the particle
Then the integral for each box can be written as:
Where
Where
To compute the integral of the 3D Gaussian over the finite box, we apply the CDF for each dimension:
To compute the derivative of
Where the first derivative is a constant:
The second derivative is a function of
Where
The derivatives of the function
- In terms of
$\mu$ :
- In terms of
$\sigma$ :
Then the derivative of
© 2024, Carlos Bueno
Project based on the Computational Molecular Science Python Cookiecutter version 1.10.