Hi Kristoffer,

If you are looking to integrate your modeling with deep-learning libraries (torch, jax, tf), you might want to have a look at SFCalculator. It's being developed by a graduate student, Minhuan Li, in my advisor's group.  It would give you access to automatic differentiation if you ever want to innovate on the refinement target function. It also supports GPU acceleration. I would say the major downside is that algorithms like solvent masking had to be made differentiable, and it is a newer project which is not as mature as CCTBX.



Cheers,
Kevin

On Thu, Oct 5, 2023 at 8:26 PM Pavel Afonine <pafonine@lbl.gov> wrote:

Hi Kristoffer,

CCTBX is a source of building blocks for Phenix, and Phenix has real- and reciprocal-space refinement programs, phenix.real_space_refine and phenix.refine, so the answer to your question is yes.

You have not specified, but I'm assuming you are looking for gradients of reciprocal space refinement target (LS, ML, MLHL, etc) and real-space target (we have only one described here: https://pubmed.ncbi.nlm.nih.gov/29872004/) with respect to model parameters such as coordinates, ADPs (isotropic, anisotropic), occupancies, f' and f'', etc.

Here are a few places:

- reciprocal space:

cctbx_project/mmtbx/refinement

files:

minimization.py
occupancies.py
rigid_body.py
group.py

regression/tst_xray_fast_gradients.py
xray/boost_python/tst_xray.py
regression/tst_xray_derivatives.py

- real space:

cctbx_project/mmtbx/refinement/real_space/individual_sites.py
cctbx_project/cctbx/maptbx/tst_real_space_refinement_simple.py
cctbx_project/cctbx/maptbx/target_and_gradients.h
cctbx_project/cctbx/maptbx/real_space_refinement_simple.py

Note, these are examples of high-level code that uses target function and its gradients to perform various kind of refinement. You'll need to do some detective work to trace to the low-level code that actually calculates gradients. Hope that's good enough starting point for you.

Also, try grep for "gradient" and "target"! Usually tests (files tst*.py serve as good examples).

Good luck!
Pavel


On 10/3/23 08:13, Kristoffer Lundgren wrote:

Hello all,

 

I am wondering if it is possible to use cctbx to calculate gradients from experimental data? Both in reciprocal and real space is of interest.

 

Are there any code examples available somewhere showcasing how this can be achieved?

 

Best regards

Kristoffer Lundgren


_______________________________________________
cctbxbb mailing list
cctbxbb@phenix-online.org
http://phenix-online.org/mailman/listinfo/cctbxbb
_______________________________________________
cctbxbb mailing list
cctbxbb@phenix-online.org
http://phenix-online.org/mailman/listinfo/cctbxbb