Package: mmtf-cppy
Themacromoleculartransmissionformat
(MMTF) is a binary encoding of biological structures.This repository holds the C++-03 compatible API, encoding and decoding
libraries. The MMTF specification can be foundhere.Prerequisites for using MMTF in C++You need the headers of the MessagePack C++ library (version 2.1.5 or newer).
If you do not have them on your machine already, you can download the "include"
directory from theMessagePack GitHub repository.How to use MMTFYou only need to include the mmtf.hpp header in your code to use MMTF.
For instance a minimal example to load an MMTF file looks as follows:#include<mmtf.hpp>intmain(intargc,char**argv){mmtf::StructureDatadata;mmtf::decodeFromFile(data,"test.mmtf");return0;}The C++ MMTF library is header only so you do not need to compile it. If you
have a source file nameddemo.cpp(e.g. including the code above), you can
generate an executabledemo.exeas follows:g++-I<MSGPACK_INCLUDE_PATH>-I<MMTF_INCLUDE_PATH>demo.cpp-odemo.exeHere,<MSGPACK_INCLUDE_PATH>and<MMTF_INCLUDE_PATH>are the paths to the
"include" directories of MessagePack and this library respectively.For your more complicated projects, aCMakeLists.txtis included for you.Python bindingsThe C++ MMTF library now can build python bindings using pybind11.  To use them
you must have A) a c++11 compatible compiler and B) python >= 3.6to install, it is as simple aspip install .(in the future possiblepip install mmtf-cppy)frommmtf_cppyimportStructureDataimportnumpyasnpimportmathdefrotation_matrix(axis,theta):"""Return the rotation matrix associated with counterclockwise rotation aboutthe given axis by theta radians.from https://stackoverflow.com/a/6802723"""axis=np.asarray(axis)axis=axis/math.sqrt(np.dot(axis,axis))a=math.cos(theta/2.0)b,c,d=-axis*math.sin(theta/2.0)aa,bb,cc,dd=a*a,b*b,c*c,d*dbc,ad,ac,ab,bd,cd=b*c,a*d,a*c,a*b,b*d,c*dreturnnp.array([[aa+bb-cc-dd,2*(bc+ad),2*(bd-ac)],[2*(bc-ad),aa+cc-bb-dd,2*(cd+ab)],[2*(bd+ac),2*(cd-ab),aa+dd-bb-cc]])theta=1.2axis=[0,0,1]sd=StructureData("my_favorite_structure.mmtf")sd.atomProperties["pymol_colorList"]=[1ifx%2==0else5forxinsd.xCoordList]xyz=np.column_stack((sd.xCoordList,sd.yCoordList,sd.zCoordList))xyz_rot=rotation_matrix(axis,theta).dot(xyz.T).Tsd.xCoordList,sd.yCoordList,sd.zCoordList=np.hsplit(xyz_rot,3)sd.write_to_file("my_favorite_structure_rot.mmtf")InstallationYou can also perform a system wide installation withcmakeandninja(ormake).To do so:mkdirbuildcdbuild
cmake-GNinja..
sudoninjainstallcmakeautomatically sets the installation directory to/usr/local/include, if you want to install it to another*include/directory
runcmakewith the command:cmake-GNinja-DCMAKE_INSTALL_PREFIX=/home/me/local..Be aware that/includeis added to the end ofDCMAKE_INSTALL_PREFIXand that is where your files are installed (i.e. the above would install at/home/me/local/include/).Examples and testsTo build the tests + examples we recommend using the following lines:# download Catch2 testing framework, msgpack-c, and the mmtf-spec test-datasetgitsubmoduleupdate--init--recursive
mkdirbuildcdbuild
cmake-GNinja-DBUILD_TESTS=ON-Dmmtf_build_examples=ON..
ninja
chmod+x./tests/mmtf_tests
./tests/mmtf_testsExample codes:mmtf_demo.cpp: Loads an MMTF file and checks internal consistency using
mmtf::StructureData::hasConsistentData../examples/mmtf_demo../submodules/mmtf_spec/test-suite/mmtf/173D.mmtftraverse.cpp: Loads an MMTF file and dumps it in human-readable forms../examples/traverse../submodules/mmtf_spec/test-suite/mmtf/173D.mmtf
./examples/traverse../submodules/mmtf_spec/test-suite/mmtf/173D.mmtfjson
./examples/traverse../submodules/mmtf_spec/test-suite/mmtf/173D.mmtfprintprint_as_pdb.cpp: Loads an MMTF file and prints it in pdb format../examples/print_as_pdb../submodules/mmtf_spec/test-suite/mmtf/173D.mmtfBenchmarkUsing the following simple code:#include<mmtf.hpp>intmain(intargc,char**argv){for(inti=1;i<argc;++i){mmtf::StructureDatasd;mmtf::decodeFromFile(sd,argv[i]);}}compiled via:g++ -Ofast -Immtf/include  -Imsgpack/include  decode_all_mmtf.cppWe are able to load 153,987 mmtf files (current size of the pdb) or 14.3GB from an SSD in 211.3 seconds (averaged over 4 runs with minimal differences between the runs).Code documentationYou can generate adoxygenbased documentation of the
library by callingdoxygenin the docs folder. You will need doxygen 1.8.11 or
later for that. Opendocs/html/index.htmlto see the generated documentation.