TorchRef Documentation
A PyTorch-based crystallographic refinement library
TorchRef is a modern crystallographic refinement package built entirely on PyTorch. By leveraging PyTorch’s automatic differentiation and GPU acceleration, TorchRef enables seamless integration with machine learning workflows and provides a flexible, extensible framework for crystallographic structure refinement.
Key Features
Native PyTorch Integration: Built on PyTorch’s
nn.ModulearchitectureAutomatic Differentiation: No manual gradient implementations required
Modular Architecture: Easily composable and extensible components
GPU Acceleration: CUDA support for fast structure factor calculations
State Management: Full
state_dictsupport for checkpointing
Getting Started
User Guide
API Reference
- torchref.cli package
- torchref.io package
- torchref.model package
- torchref.refinement package
- torchref.restraints package
- torchref.scaling package
- torchref.symmetry package
CellSpaceGroupspacegroup_to_str()get_symmetry_operations()get_operations_as_tensors()is_same_spacegroup()get_point_group()get_crystal_system()is_centrosymmetric()n_operations()SymmetryMapSymmetry()MapSymmetryDirectReciprocalSymmetry()ReciprocalSymmetryGridexpand_hkl()complete_hkl()reduce_hkl()canonicalize_hkl()expand_reflections()expand_reciprocal_grid()get_symmetry_grid_requirements()check_grid_compatibility()recommend_grid_size()find_fft_friendly_size()is_fft_friendly()calculate_optimal_grid_size()- Submodules
- torchref.base package
- Submodules (New Organization)
- Legacy Submodules (For Backward Compatibility)
FrenchWilsonCachedRadiusMaskReciprocalSymmetryExtractorcartesian_to_fractional_torch()fractional_to_cartesian_torch()get_fractional_matrix()get_inv_fractional_matrix_torch()cartesian_to_fractional()fractional_to_cartesian()get_inv_fractional_matrix()convert_coords_to_fractional()smallest_diff()smallest_diff_aniso()reciprocal_basis_matrix()reciprocal_basis_matrix_numpy()get_scattering_vectors()get_scattering_vectors_numpy()get_s()get_d_spacing()compute_d_spacing_batch()generate_possible_hkl()place_on_grid()extract_structure_factor_from_grid()apply_translation_phase()interpolate_structure_factor_from_grid()interpolate_complex_from_grid()trilinear_interpolate_patterson()compute_symmetry_equivalent_hkls()compute_translation_phases()extract_structure_factors_with_symmetry()interpolate_for_rotation()smooth_reciprocal_grid()iso_structure_factor_torched()iso_structure_factor_torched_no_complex()aniso_structure_factor_torched()aniso_structure_factor_torched_no_complex()anharmonic_correction()anharmonic_correction_no_complex()core_deformation()multiplication_quasi_complex_tensor()vectorized_add_to_map()vectorized_add_to_map_aniso()scatter_add_nd()scatter_add_nd_super_slow()find_relevant_voxels()excise_angstrom_radius_around_coord()add_to_solvent_mask()add_to_phenix_mask()find_solvent_voids()fft()ifft()get_real_grid()find_grid_size()get_real_grid_numpy()get_grids()put_hkl_on_grid()get_scattering_factors()get_scattering_factors_unique()get_parametrization_for_elements()calc_scattering_factors_paramtetrization()compute_radial_shells()assign_to_shells()compute_anisotropy_correction()compute_shell_cv()fit_anisotropy_correction()apply_anisotropy_correction()F_squared_to_E_values()rotate_coords_torch()rotate_coords_numpy()axis_angle_to_rotation_matrix()rotation_matrix_to_axis_angle()quaternion_to_rotation_matrix()random_rotation_uniform()superpose_vectors_robust_torch()superpose_vectors_robust()align_torch()align_pdbs()get_alignment_matrix()apply_transformation()apply_transformation_numpy()invert_transformation_matrix()get_rfactor_torch()get_rfactor()rfactor()get_rfactors()bin_wise_rfactors()calc_outliers()calc_outliers_numpy()nll_xray()nll_xray_sum()nll_xray_lognormal()log_loss()estimate_sigma_I()estimate_sigma_F()gaussian_to_lognormal_sigma()gaussian_to_lognormal_mu()compute_metric_tensor()precompute_fractional_coords()warmup()get_cache_dir()clear_cache()warmup_cuda_operations()get_cached_radius_offsets()- Subpackages
- Submodules
- torchref.utils package
ParameterFingerprintCachedForwardMixinDeviceMixinDeviceMovementMixinresolve_device()TensorMasksTensorDictModuleReferencesave_map()sanitize_pdb_dataframe()parse_phenix_selection()create_selection_mask()DebugMixinprint_module_summary()StatEntrystat()filter_stats()flatten_stats()format_stats_table()HyperparameterMixinconvert_to_serializable()gradnorm()validate_loss()NonFiniteLossErrorreset_diagnostic_budget()collect_loss_leaves()- Submodules
Development