├── UnitTests ├── RMSD │ ├── __init__.py │ └── Coords2RMSD │ │ ├── __init__.py │ │ ├── test_backward.py │ │ └── test.py ├── FullAtomModel │ ├── Angles2Coords │ │ ├── __init__.py │ │ ├── simple_test.py │ │ ├── utils.py │ │ └── test.py │ ├── PDB2Coords │ │ ├── __init__.py │ │ └── test.py │ ├── Coords2TypedCoords │ │ ├── __init__.py │ │ └── test.py │ ├── CoordsTransform │ │ ├── __init__.py │ │ ├── test_backward.py │ │ └── test_forward.py │ └── __init__.py ├── ReducedModel │ ├── __init__.py │ └── Angles2Backbone │ │ ├── __init__.py │ │ ├── test_forward_simple.py │ │ ├── test.py │ │ ├── test_backward.py │ │ └── test_forward.py ├── Volume │ ├── TypedCoords2Volume │ │ ├── __init__.py │ │ ├── test_forward.py │ │ ├── test_backward.py │ │ └── test.py │ ├── VolumeConvolution │ │ ├── __init__.py │ │ ├── grad_example.py │ │ ├── test_backward.py │ │ └── test_forward.py │ ├── __init__.py │ ├── Select │ │ └── test.py │ ├── VolumeRMSD │ │ └── test_forward.py │ └── VolumeRotation │ │ └── test_forward.py └── main.py ├── TorchProteinLibrary ├── RMSD │ ├── __init__.py │ └── Coords2RMSD │ │ ├── __init__.py │ │ └── Coords2RMSD.py ├── Volume │ ├── Select │ │ ├── __init__.py │ │ └── SelectVolume.py │ ├── VolumeRMSD │ │ ├── __init__.py │ │ └── VolumeRMSD.py │ ├── VolumeRotation │ │ ├── __init__.py │ │ └── VolumeRotation.py │ ├── TypedCoords2Volume │ │ ├── __init__.py │ │ └── TypedCoords2Volume.py │ ├── VolumeConvolution │ │ ├── __init__.py │ │ └── VolumeConvolution.py │ └── __init__.py ├── FullAtomModel │ ├── CoordsTransform │ │ └── __init__.py │ ├── Angles2Coords │ │ ├── __init__.py │ │ └── Angles2Coords.py │ ├── Coords2TypedCoords │ │ ├── __init__.py │ │ └── Coords2TypedCoords.py │ ├── PDB2Coords │ │ ├── __init__.py │ │ └── PDB2Coords.py │ └── __init__.py ├── ReducedModel │ ├── __init__.py │ └── Angles2Backbone │ │ ├── __init__.py │ │ └── Angles2Backbone.py └── __init__.py ├── docs ├── Fig │ ├── Tensors.png │ ├── Amino-acid.png │ ├── MolecularGraph.png │ ├── VolumeSelect.png │ ├── example_graph.png │ └── examples │ │ ├── ExampleAngles2Coords.png │ │ ├── ExampleFitBackbone.mp4 │ │ ├── ExampleAngles2Backbone.png │ │ ├── ExampleFitBackboneTrace.png │ │ ├── ExampleTypedCoords2Volume.png │ │ └── ExamplePDB2CoordsUnordered.png ├── Examples │ ├── ExampleFitBackboneTrace.png │ ├── FullAtomModel │ │ ├── ExampleAngles2Coords.png │ │ ├── ExamplePDB2CoordsUnordered.png │ │ ├── ExamplePDB2CoordsUnordered.py │ │ └── ExampleAngles2Coords.py │ ├── ReducedModel │ │ └── ExampleAngles2Backbone.py │ ├── Volume │ │ └── ExampleTypedCoords2Volume.py │ └── fitBackbone.py └── css │ └── default.css ├── Layers ├── Volume │ ├── VolumeRotation │ │ ├── volumeRotation_interface.h │ │ └── volumeRotation_interface.cpp │ ├── RotateGrid.h │ ├── Volume2Xplor │ │ ├── volume2xplor_interface.h │ │ └── volume2xplor_interface.cpp │ ├── VolumeConv.h │ ├── VolumeRMSD.h │ ├── Select │ │ ├── select_interface.h │ │ └── select_interface.cpp │ ├── VolumeRMSD │ │ ├── volumeRMSD_interface.h │ │ └── volumeRMSD_interface.cpp │ ├── VolumeConvolution │ │ ├── volumeConvolution_interface.h │ │ └── volumeConvolution_interface.cpp │ ├── TypedCoords2Volume │ │ ├── typedcoords2volume_interface.h │ │ └── typedcoords2volume_interface.cpp │ ├── Kernels.h │ ├── main.cpp │ ├── VolumeRMSD.cu │ └── RotateGrid.cu ├── RMSD │ ├── main.cpp │ ├── RMSDKernels.h │ ├── Coords2RMSD │ │ └── coords2rmsd_interface.h │ └── RMSDKernels.cu ├── FullAtomModel │ ├── PDB2Coords │ │ └── pdb2coords_interface.h │ ├── TransformCUDAKernels.h │ ├── Angles2Coords │ │ └── angles2coords_interface.h │ ├── Coords2TypedCoords │ │ └── coords2typedcoords_interface.h │ ├── cPDBLoader.h │ ├── CoordsTransform │ │ ├── coordsTransformGPU_interface.h │ │ └── coordsTransform_interface.h │ ├── cGeometry.h │ ├── main.cpp │ ├── cRigidGroup.h │ ├── cGeometry.cpp │ └── cConformation.h └── ReducedModel │ ├── main.cpp │ ├── cBackboneProteinCUDAKernels.h │ ├── cBackboneProteinCPUKernels.hpp │ └── Angles2Backbone │ ├── angles2backbone_interface.h │ └── angles2backbone_interface.cpp ├── Math ├── CMakeLists.txt ├── cMatrix44.h ├── cMatrix33.h ├── cVector3.h ├── nUtil.h ├── cVector3.cpp └── cMathCUDAKernels.h ├── .gitignore ├── Benchmark ├── main.py ├── core.py ├── lstm.py ├── rmsd.py ├── reducedmodel.py └── fullatommodel.py ├── LICENSE ├── README.md └── setup.py /UnitTests/RMSD/__init__.py: -------------------------------------------------------------------------------- 1 | from .Coords2RMSD import * -------------------------------------------------------------------------------- /UnitTests/RMSD/Coords2RMSD/__init__.py: -------------------------------------------------------------------------------- 1 | from .test import * -------------------------------------------------------------------------------- /UnitTests/FullAtomModel/Angles2Coords/__init__.py: -------------------------------------------------------------------------------- 1 | from .test import * -------------------------------------------------------------------------------- /UnitTests/FullAtomModel/PDB2Coords/__init__.py: -------------------------------------------------------------------------------- 1 | from .test import * -------------------------------------------------------------------------------- /UnitTests/ReducedModel/__init__.py: -------------------------------------------------------------------------------- 1 | from .Angles2Backbone import * -------------------------------------------------------------------------------- /UnitTests/Volume/TypedCoords2Volume/__init__.py: -------------------------------------------------------------------------------- 1 | from .test import * -------------------------------------------------------------------------------- /UnitTests/Volume/VolumeConvolution/__init__.py: -------------------------------------------------------------------------------- 1 | from .test import * -------------------------------------------------------------------------------- /TorchProteinLibrary/RMSD/__init__.py: -------------------------------------------------------------------------------- 1 | from .Coords2RMSD import Coords2RMSD -------------------------------------------------------------------------------- /UnitTests/FullAtomModel/Coords2TypedCoords/__init__.py: -------------------------------------------------------------------------------- 1 | from .test import * -------------------------------------------------------------------------------- /UnitTests/FullAtomModel/CoordsTransform/__init__.py: -------------------------------------------------------------------------------- 1 | from .test import * -------------------------------------------------------------------------------- /UnitTests/ReducedModel/Angles2Backbone/__init__.py: -------------------------------------------------------------------------------- 1 | from .test import * -------------------------------------------------------------------------------- /TorchProteinLibrary/Volume/Select/__init__.py: -------------------------------------------------------------------------------- 1 | from .SelectVolume import SelectVolume -------------------------------------------------------------------------------- /TorchProteinLibrary/Volume/VolumeRMSD/__init__.py: -------------------------------------------------------------------------------- 1 | from .VolumeRMSD import VolumeRMSD -------------------------------------------------------------------------------- /TorchProteinLibrary/RMSD/Coords2RMSD/__init__.py: -------------------------------------------------------------------------------- 1 | from .Coords2RMSD import Coords2RMSD -------------------------------------------------------------------------------- /TorchProteinLibrary/FullAtomModel/CoordsTransform/__init__.py: -------------------------------------------------------------------------------- 1 | from .CoordsTransform import * -------------------------------------------------------------------------------- /TorchProteinLibrary/ReducedModel/__init__.py: -------------------------------------------------------------------------------- 1 | from .Angles2Backbone import Angles2Backbone 2 | 3 | -------------------------------------------------------------------------------- /TorchProteinLibrary/Volume/VolumeRotation/__init__.py: -------------------------------------------------------------------------------- 1 | from .VolumeRotation import VolumeRotation -------------------------------------------------------------------------------- /UnitTests/Volume/__init__.py: -------------------------------------------------------------------------------- 1 | from .VolumeConvolution import * 2 | from .TypedCoords2Volume import * -------------------------------------------------------------------------------- /TorchProteinLibrary/FullAtomModel/Angles2Coords/__init__.py: -------------------------------------------------------------------------------- 1 | from .Angles2Coords import Angles2Coords -------------------------------------------------------------------------------- /TorchProteinLibrary/ReducedModel/Angles2Backbone/__init__.py: -------------------------------------------------------------------------------- 1 | from .Angles2Backbone import Angles2Backbone -------------------------------------------------------------------------------- /TorchProteinLibrary/Volume/TypedCoords2Volume/__init__.py: -------------------------------------------------------------------------------- 1 | from .TypedCoords2Volume import TypedCoords2Volume -------------------------------------------------------------------------------- /TorchProteinLibrary/Volume/VolumeConvolution/__init__.py: -------------------------------------------------------------------------------- 1 | from .VolumeConvolution import VolumeConvolution -------------------------------------------------------------------------------- /docs/Fig/Tensors.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/Tensors.png -------------------------------------------------------------------------------- /TorchProteinLibrary/FullAtomModel/Coords2TypedCoords/__init__.py: -------------------------------------------------------------------------------- 1 | from .Coords2TypedCoords import Coords2TypedCoords -------------------------------------------------------------------------------- /docs/Fig/Amino-acid.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/Amino-acid.png -------------------------------------------------------------------------------- /docs/Fig/MolecularGraph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/MolecularGraph.png -------------------------------------------------------------------------------- /docs/Fig/VolumeSelect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/VolumeSelect.png -------------------------------------------------------------------------------- /docs/Fig/example_graph.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/example_graph.png -------------------------------------------------------------------------------- /TorchProteinLibrary/FullAtomModel/PDB2Coords/__init__.py: -------------------------------------------------------------------------------- 1 | from .PDB2Coords import PDB2CoordsOrdered, PDB2CoordsUnordered, writePDB -------------------------------------------------------------------------------- /TorchProteinLibrary/__init__.py: -------------------------------------------------------------------------------- 1 | from . import FullAtomModel 2 | from . import Volume 3 | from . import ReducedModel 4 | from . import RMSD -------------------------------------------------------------------------------- /Layers/Volume/VolumeRotation/volumeRotation_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | void VolumeGenGrid( torch::Tensor rotations, torch::Tensor grid); -------------------------------------------------------------------------------- /docs/Examples/ExampleFitBackboneTrace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Examples/ExampleFitBackboneTrace.png -------------------------------------------------------------------------------- /docs/Fig/examples/ExampleAngles2Coords.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/examples/ExampleAngles2Coords.png -------------------------------------------------------------------------------- /docs/Fig/examples/ExampleFitBackbone.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/examples/ExampleFitBackbone.mp4 -------------------------------------------------------------------------------- /docs/Fig/examples/ExampleAngles2Backbone.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/examples/ExampleAngles2Backbone.png -------------------------------------------------------------------------------- /docs/Fig/examples/ExampleFitBackboneTrace.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/examples/ExampleFitBackboneTrace.png -------------------------------------------------------------------------------- /docs/Fig/examples/ExampleTypedCoords2Volume.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/examples/ExampleTypedCoords2Volume.png -------------------------------------------------------------------------------- /Layers/Volume/RotateGrid.h: -------------------------------------------------------------------------------- 1 | #define REAL float 2 | // #define REAL double 3 | 4 | void cpu_RotateGrid(REAL *d_rotations, REAL *d_grid, int batch_size, int volume_size); -------------------------------------------------------------------------------- /Layers/Volume/Volume2Xplor/volume2xplor_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | void Volume2Xplor( torch::Tensor volume, const char *filename, float resolution); -------------------------------------------------------------------------------- /UnitTests/FullAtomModel/__init__.py: -------------------------------------------------------------------------------- 1 | from .Angles2Coords import * 2 | from .Coords2TypedCoords import * 3 | from .CoordsTransform import * 4 | from .PDB2Coords import * -------------------------------------------------------------------------------- /docs/Fig/examples/ExamplePDB2CoordsUnordered.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Fig/examples/ExamplePDB2CoordsUnordered.png -------------------------------------------------------------------------------- /docs/Examples/FullAtomModel/ExampleAngles2Coords.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Examples/FullAtomModel/ExampleAngles2Coords.png -------------------------------------------------------------------------------- /TorchProteinLibrary/FullAtomModel/__init__.py: -------------------------------------------------------------------------------- 1 | from .Angles2Coords import * 2 | from .PDB2Coords import * 3 | from .CoordsTransform import * 4 | from .Coords2TypedCoords import * 5 | -------------------------------------------------------------------------------- /docs/Examples/FullAtomModel/ExamplePDB2CoordsUnordered.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lamoureux-lab/TorchProteinLibrary/HEAD/docs/Examples/FullAtomModel/ExamplePDB2CoordsUnordered.png -------------------------------------------------------------------------------- /UnitTests/main.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from FullAtomModel import * 3 | from Volume import * 4 | from RMSD import * 5 | from ReducedModel import * 6 | 7 | if __name__=='__main__': 8 | unittest.main() -------------------------------------------------------------------------------- /Math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR) 2 | CMAKE_POLICY(VERSION 2.8) 3 | 4 | ADD_LIBRARY(TH_MATH STATIC cVector3.cpp cMatrix33.cpp cMatrix44.cpp) 5 | TARGET_LINK_LIBRARIES(TH_MATH) 6 | -------------------------------------------------------------------------------- /TorchProteinLibrary/Volume/__init__.py: -------------------------------------------------------------------------------- 1 | from .TypedCoords2Volume import TypedCoords2Volume 2 | from .Select import SelectVolume 3 | from .VolumeConvolution import VolumeConvolution 4 | from .VolumeRotation import VolumeRotation 5 | from .VolumeRMSD import VolumeRMSD -------------------------------------------------------------------------------- /Layers/Volume/VolumeConv.h: -------------------------------------------------------------------------------- 1 | 2 | #define REAL float 3 | // #define REAL double 4 | 5 | 6 | void cpu_VolumeConv(REAL *d_volume1, REAL *d_volume2, REAL *d_output, int batch_size, int volume_size, bool conjugate); 7 | // Computes F(tau) = \int vol1(r)vol2(tau-r) dr 8 | -------------------------------------------------------------------------------- /Layers/Volume/VolumeRMSD.h: -------------------------------------------------------------------------------- 1 | #define REAL float 2 | 3 | void gpu_VolumeRMSD(REAL *d_volume, 4 | REAL add, 5 | REAL T0_x, REAL T0_y, REAL T0_z, 6 | REAL D_x, REAL D_y, REAL D_z, 7 | int volume_size, float resolution); -------------------------------------------------------------------------------- /Layers/RMSD/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 5 | m.def("Coords2RMSDGPU_forward", &Coords2RMSDGPU_forward, "Coords2RMSD forward on GPU"); 6 | m.def("Coords2RMSD_forward", &Coords2RMSD_forward, "Coords2RMSD forward on CPU"); 7 | } -------------------------------------------------------------------------------- /Layers/Volume/Select/select_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void SelectVolume_forward( torch::Tensor volume, 4 | torch::Tensor coords, 5 | torch::Tensor num_atoms, 6 | torch::Tensor features, 7 | float res 8 | ); -------------------------------------------------------------------------------- /Layers/Volume/VolumeRMSD/volumeRMSD_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | void VolumeGenRMSD( torch::Tensor coords, 3 | torch::Tensor num_atoms, 4 | torch::Tensor R0, 5 | torch::Tensor R1, 6 | torch::Tensor T0, 7 | torch::Tensor translation_volume, 8 | float resolution); -------------------------------------------------------------------------------- /Layers/FullAtomModel/PDB2Coords/pdb2coords_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | // void PDB2CoordsOrdered(torch::Tensor filenames, torch::Tensor coords, torch::Tensor res_names, torch::Tensor atom_names, torch::Tensor mask); 3 | void PDB2CoordsUnordered(torch::Tensor filenames, torch::Tensor coords, torch::Tensor chain_names, torch::Tensor res_names, torch::Tensor res_nums, torch::Tensor atom_names, torch::Tensor num_atoms); 4 | -------------------------------------------------------------------------------- /UnitTests/FullAtomModel/Angles2Coords/simple_test.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import argparse 4 | import torch 5 | from TorchProteinLibrary import FullAtomModel 6 | 7 | if __name__=="__main__": 8 | a2c = FullAtomModel.Angles2Coords() 9 | residues = ["AAAAAAAA"] 10 | angles = torch.zeros(1, 8, len(residues[0]), dtype=torch.double, device='cpu') 11 | angles[:,2] = 3.14 12 | protein, res_names, atom_names, num_atoms = a2c(angles, residues) -------------------------------------------------------------------------------- /Layers/RMSD/RMSDKernels.h: -------------------------------------------------------------------------------- 1 | template 2 | void gpu_correlationMatrix( T *d_coords1, //input: coordinates 1 3 | T *d_coords2, //input: coordinates 2 4 | double *TMat, //output: correlation matrix 5 | int *num_atoms, 6 | int batch_size, 7 | int atoms_stride); 8 | template 9 | void gpu_computeR2( T *d_coords, int num_atoms, double *R2); 10 | -------------------------------------------------------------------------------- /TorchProteinLibrary/Volume/VolumeRMSD/VolumeRMSD.py: -------------------------------------------------------------------------------- 1 | import torch 2 | import torch.nn.functional as F 3 | from torch.autograd import Function 4 | import math 5 | 6 | import sys 7 | import os 8 | 9 | import _Volume 10 | 11 | def VolumeRMSD(coords, num_atoms, R0, R1, T0, resolution, volume_size): 12 | batch_size = coords.size(0) 13 | rmsdVolume = torch.zeros(batch_size, volume_size, volume_size, volume_size, dtype=torch.float, device='cuda') 14 | _Volume.VolumeGenRMSD(coords, num_atoms, R0, R1, T0, rmsdVolume, resolution) 15 | return rmsdVolume 16 | -------------------------------------------------------------------------------- /Layers/ReducedModel/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) { 5 | m.def("Angles2BackboneCPU_forward", &Angles2BackboneCPU_forward, "Angles2Backbone cpu forward"); 6 | m.def("Angles2BackboneCPU_backward", &Angles2BackboneCPU_backward, "Angles2Backbone cpu backward"); 7 | m.def("Angles2BackboneGPU_forward", &Angles2BackboneGPU_forward, "Angles2Backbone gpu forward"); 8 | m.def("Angles2BackboneGPU_backward", &Angles2BackboneGPU_backward, "Angles2Backbone gpu backward"); 9 | } -------------------------------------------------------------------------------- /Layers/Volume/VolumeConvolution/volumeConvolution_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | void VolumeConvolution_forward( torch::Tensor volume1, 3 | torch::Tensor volume2, 4 | torch::Tensor output); 5 | void VolumeConvolution_backward( torch::Tensor gradOutput, 6 | torch::Tensor gradVolume1, 7 | torch::Tensor gradVolume2, 8 | torch::Tensor volume1, 9 | torch::Tensor volume2); -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | #Temp files 2 | *~ 3 | *.png 4 | *.pdb 5 | *.xplor 6 | *.tex 7 | *.svg 8 | *.code-workspace 9 | *.egg-info 10 | *.pkl 11 | *.js 12 | *.bib 13 | *.pdf 14 | *.sty 15 | *.gif 16 | *.txt 17 | 18 | #Python 19 | *.pyc 20 | 21 | # Prerequisites 22 | *.d 23 | 24 | # Compiled Object files 25 | *.slo 26 | *.lo 27 | *.o 28 | *.obj 29 | 30 | # Precompiled Headers 31 | *.gch 32 | *.pch 33 | 34 | # Compiled Dynamic libraries 35 | *.so 36 | *.dylib 37 | *.dll 38 | 39 | # Fortran module files 40 | *.mod 41 | *.smod 42 | 43 | # Compiled Static libraries 44 | *.lai 45 | *.la 46 | *.a 47 | *.lib 48 | 49 | # Executables 50 | *.exe 51 | *.out 52 | *.app 53 | -------------------------------------------------------------------------------- /Layers/Volume/VolumeRotation/volumeRotation_interface.cpp: -------------------------------------------------------------------------------- 1 | #include "volumeRotation_interface.h" 2 | #include 3 | #include 4 | #include 5 | 6 | 7 | void VolumeGenGrid( torch::Tensor rotations, torch::Tensor grid){ 8 | CHECK_GPU_INPUT_TYPE(rotations, torch::kFloat32); 9 | CHECK_GPU_INPUT_TYPE(grid, torch::kFloat32); 10 | if(rotations.ndimension()!=3 || grid.ndimension()!=5){ 11 | ERROR("incorrect input dimension"); 12 | } 13 | int batch_size = rotations.size(0); 14 | int size = grid.size(1); 15 | cpu_RotateGrid(rotations.data(), grid.data(), batch_size, size); 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Layers/RMSD/Coords2RMSD/coords2rmsd_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | void Coords2RMSDGPU_forward( torch::Tensor centered_coords_src, 3 | torch::Tensor centered_coords_dst, 4 | torch::Tensor output, 5 | torch::Tensor num_atoms, 6 | torch::Tensor UT 7 | ); 8 | void Coords2RMSD_forward( torch::Tensor centered_coords_src, 9 | torch::Tensor centered_coords_dst, 10 | torch::Tensor output, 11 | torch::Tensor num_atoms, 12 | torch::Tensor UT 13 | ); -------------------------------------------------------------------------------- /Layers/Volume/TypedCoords2Volume/typedcoords2volume_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | void TypedCoords2Volume_forward( torch::Tensor input_coords, 3 | torch::Tensor volume, 4 | torch::Tensor num_atoms_of_type, 5 | torch::Tensor offsets, 6 | float resolution); 7 | void TypedCoords2Volume_backward( torch::Tensor grad_volume, 8 | torch::Tensor grad_coords, 9 | torch::Tensor coords, 10 | torch::Tensor num_atoms_of_type, 11 | torch::Tensor offsets, 12 | float resolution); -------------------------------------------------------------------------------- /Layers/ReducedModel/cBackboneProteinCUDAKernels.h: -------------------------------------------------------------------------------- 1 | 2 | #define REAL float 3 | template 4 | void gpu_computeCoordinatesBackbone(T *angles, 5 | T *dr, 6 | T *dR_dangle, 7 | int *length, 8 | int batch_size, 9 | int angles_stride); 10 | template 11 | void gpu_computeDerivativesBackbone(T *angles, 12 | T *atoms, 13 | T *A, 14 | int *length, 15 | int batch_size, 16 | int angles_stride); 17 | template 18 | void gpu_backwardFromCoordsBackbone(T *angles, 19 | T *dR_dangle, 20 | T *A, 21 | int *length, 22 | int batch_size, 23 | int angles_stride); -------------------------------------------------------------------------------- /Layers/Volume/Kernels.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template 4 | void gpu_computeCoords2Volume( T *coords, 5 | int *num_atoms_of_type, 6 | int *offsets, 7 | T *volume, 8 | int spatial_dim, 9 | int num_atom_types, 10 | float res); 11 | 12 | template 13 | void gpu_computeVolume2Coords( T *coords, 14 | T* grad, 15 | int *num_atoms_of_type, 16 | int *offsets, 17 | T *volume, 18 | int spatial_dim, 19 | int num_atom_types, 20 | float res); 21 | 22 | void gpu_selectFromTensor( float *features, int num_features, 23 | float* volume, int spatial_dim, 24 | float *coords, int num_atoms, int max_num_atoms, 25 | float res); -------------------------------------------------------------------------------- /Layers/FullAtomModel/TransformCUDAKernels.h: -------------------------------------------------------------------------------- 1 | template void gpu_CoordsTranslateForward(T *coords_src, T *coords_dst, T *translation, int *num_atoms, int batch_size, int atoms_stride); 2 | template void gpu_CoordsTranslateBackward(T *grad_coords_output, T *grad_coords_input, T *translation, int *num_atoms, int batch_size, int atoms_stride); 3 | 4 | template void gpu_CoordsRotateForward(T *coords_src, T *coords_dst, T *rotation, int *num_atoms, int batch_size, int atoms_stride); 5 | template void gpu_CoordsRotateBackward(T *grad_coords_output, T *grad_coords_input, T *rotation, int *num_atoms, int batch_size, int atoms_stride); 6 | 7 | template void gpu_Coords2CenterForward(T *coords_src, T *center, int *num_atoms, int batch_size, int atoms_stride); 8 | template void gpu_Coords2CenterBackward(T *grad_T, T *grad_coords, int *num_atoms, int batch_size, int atoms_stride); 9 | 10 | 11 | -------------------------------------------------------------------------------- /Benchmark/main.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.autograd import profiler 3 | from TorchProteinLibrary import ReducedModel, FullAtomModel, RMSD 4 | import numpy as np 5 | 6 | if __name__=='__main__': 7 | a2c = FullAtomModel.Angles2Coords() 8 | sequences = ['GGMLGWAHFGY'] 9 | 10 | #Setting conformation to alpha-helix 11 | angles = torch.zeros(len(sequences), 7, len(sequences[-1]), dtype=torch.double, device='cpu') 12 | angles.data[:,0,:] = -1.047 13 | angles.data[:,1,:] = -0.698 14 | angles.data[:,2:,:] = 110.4*np.pi/180.0 15 | 16 | #Converting angles to coordinates 17 | with profiler.profile() as prof: 18 | coords, res_names, atom_names, num_atoms = a2c(angles, sequences) 19 | # coords.backward() 20 | dur = 0.0 21 | for evt in prof.function_events: 22 | dur += evt.cpu_interval.elapsed_us() 23 | print(dur/1000.0, 'ms') 24 | 25 | # print(prof) 26 | # print(prof.total_average()) 27 | -------------------------------------------------------------------------------- /Layers/FullAtomModel/Angles2Coords/angles2coords_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | void Angles2Coords_forward( at::Tensor sequences, 3 | at::Tensor input_angles, 4 | at::Tensor output_coords, 5 | at::Tensor res_names, 6 | at::Tensor atom_names 7 | ); 8 | 9 | void Angles2Coords_backward( at::Tensor grad_atoms, 10 | at::Tensor grad_angles, 11 | at::Tensor sequences, 12 | at::Tensor input_angles 13 | ); 14 | void Angles2Coords_save( const char* sequence, 15 | at::Tensor input_angles, 16 | const char* output_filename, 17 | const char mode 18 | ); 19 | int getSeqNumAtoms( const char *sequence); -------------------------------------------------------------------------------- /Layers/ReducedModel/cBackboneProteinCPUKernels.hpp: -------------------------------------------------------------------------------- 1 | template 2 | void cpu_computeCoordinatesBackbone( T *angles, 3 | T *dr, 4 | T *dR_dangle, 5 | int *length, 6 | int batch_size, 7 | int angles_stride); 8 | template 9 | void cpu_computeDerivativesBackbone( T *angles, 10 | T *dR_dangle, 11 | T *A, 12 | int *length, 13 | int batch_size, 14 | int angles_stride); 15 | template 16 | void cpu_backwardFromCoordsBackbone( T *gradInput, 17 | T *gradOutput, 18 | T *dR_dangle, 19 | int *length, 20 | int batch_size, 21 | int angles_stride); -------------------------------------------------------------------------------- /TorchProteinLibrary/Volume/Select/SelectVolume.py: -------------------------------------------------------------------------------- 1 | import torch 2 | from torch.autograd import Function 3 | from torch.autograd import Variable 4 | from torch.nn.modules.module import Module 5 | import _Volume 6 | import math 7 | 8 | class SelectVolume: 9 | def __init__(self, box_size_bins=120, box_size_ang=120): 10 | self.box_size_bins = box_size_bins 11 | self.box_size_ang = box_size_ang 12 | self.resolution = float(box_size_ang)/float(box_size_bins) 13 | 14 | def __call__(self, volume, coords, num_atoms): 15 | if len(volume.size())==5 and len(coords.size())==2: 16 | batch_size = volume.size(0) 17 | num_features = volume.size(1) 18 | max_num_atoms = int(coords.size(1)/3) 19 | features = torch.zeros(batch_size, num_features, max_num_atoms, dtype=torch.float, device='cuda') 20 | else: 21 | raise(Exception("SelectVolume: Wrong input sizes", volume.size(), coords.size())) 22 | 23 | _Volume.SelectVolume_forward(volume, coords, num_atoms, features, self.resolution) 24 | 25 | return features 26 | 27 | -------------------------------------------------------------------------------- /Layers/FullAtomModel/Coords2TypedCoords/coords2typedcoords_interface.h: -------------------------------------------------------------------------------- 1 | #include 2 | void Coords2TypedCoords_forward( torch::Tensor input_coords, 3 | torch::Tensor res_names, 4 | torch::Tensor atom_names, 5 | torch::Tensor input_num_atoms, 6 | torch::Tensor output_coords, 7 | torch::Tensor output_num_atoms_of_type, 8 | torch::Tensor output_offsets, 9 | torch::Tensor output_atom_indexes 10 | ); 11 | void Coords2TypedCoords_backward( torch::Tensor grad_typed_coords, 12 | torch::Tensor grad_flat_coords, 13 | torch::Tensor num_atoms_of_type, 14 | torch::Tensor offsets, 15 | torch::Tensor atom_indexes 16 | ); -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 George 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Layers/Volume/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include