hillclimber 0.1.6__cp314-cp314t-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (475) hide show
  1. hillclimber/__init__.py +41 -0
  2. hillclimber/actions.py +53 -0
  3. hillclimber/analysis.py +590 -0
  4. hillclimber/biases.py +293 -0
  5. hillclimber/calc.py +22 -0
  6. hillclimber/cvs.py +1070 -0
  7. hillclimber/interfaces.py +133 -0
  8. hillclimber/metadynamics.py +416 -0
  9. hillclimber/nodes.py +6 -0
  10. hillclimber/opes.py +359 -0
  11. hillclimber/pycv.py +362 -0
  12. hillclimber/selectors.py +230 -0
  13. hillclimber/virtual_atoms.py +341 -0
  14. hillclimber-0.1.6.dist-info/METADATA +325 -0
  15. hillclimber-0.1.6.dist-info/RECORD +475 -0
  16. hillclimber-0.1.6.dist-info/WHEEL +6 -0
  17. hillclimber-0.1.6.dist-info/entry_points.txt +8 -0
  18. hillclimber-0.1.6.dist-info/licenses/LICENSE +165 -0
  19. hillclimber-0.1.6.dist-info/sboms/auditwheel.cdx.json +1 -0
  20. hillclimber.libs/libgomp-a49a47f9.so.1.0.0 +0 -0
  21. plumed/__init__.py +104 -0
  22. plumed/_lib/bin/plumed +0 -0
  23. plumed/_lib/bin/plumed-config +9 -0
  24. plumed/_lib/bin/plumed-patch +9 -0
  25. plumed/_lib/include/plumed/adjmat/AdjacencyMatrixBase.h +659 -0
  26. plumed/_lib/include/plumed/adjmat/ContactMatrix.h +59 -0
  27. plumed/_lib/include/plumed/asmjit/arch.h +228 -0
  28. plumed/_lib/include/plumed/asmjit/arm.h +43 -0
  29. plumed/_lib/include/plumed/asmjit/asmjit.h +69 -0
  30. plumed/_lib/include/plumed/asmjit/asmjit_apibegin.h +143 -0
  31. plumed/_lib/include/plumed/asmjit/asmjit_apiend.h +93 -0
  32. plumed/_lib/include/plumed/asmjit/asmjit_build.h +971 -0
  33. plumed/_lib/include/plumed/asmjit/assembler.h +183 -0
  34. plumed/_lib/include/plumed/asmjit/base.h +56 -0
  35. plumed/_lib/include/plumed/asmjit/codebuilder.h +944 -0
  36. plumed/_lib/include/plumed/asmjit/codecompiler.h +767 -0
  37. plumed/_lib/include/plumed/asmjit/codeemitter.h +528 -0
  38. plumed/_lib/include/plumed/asmjit/codeholder.h +777 -0
  39. plumed/_lib/include/plumed/asmjit/constpool.h +286 -0
  40. plumed/_lib/include/plumed/asmjit/cpuinfo.h +402 -0
  41. plumed/_lib/include/plumed/asmjit/func.h +1327 -0
  42. plumed/_lib/include/plumed/asmjit/globals.h +370 -0
  43. plumed/_lib/include/plumed/asmjit/inst.h +137 -0
  44. plumed/_lib/include/plumed/asmjit/logging.h +317 -0
  45. plumed/_lib/include/plumed/asmjit/misc_p.h +103 -0
  46. plumed/_lib/include/plumed/asmjit/moved_string.h +318 -0
  47. plumed/_lib/include/plumed/asmjit/operand.h +1599 -0
  48. plumed/_lib/include/plumed/asmjit/osutils.h +207 -0
  49. plumed/_lib/include/plumed/asmjit/regalloc_p.h +597 -0
  50. plumed/_lib/include/plumed/asmjit/runtime.h +227 -0
  51. plumed/_lib/include/plumed/asmjit/simdtypes.h +1104 -0
  52. plumed/_lib/include/plumed/asmjit/utils.h +1387 -0
  53. plumed/_lib/include/plumed/asmjit/vmem.h +183 -0
  54. plumed/_lib/include/plumed/asmjit/x86.h +45 -0
  55. plumed/_lib/include/plumed/asmjit/x86assembler.h +125 -0
  56. plumed/_lib/include/plumed/asmjit/x86builder.h +117 -0
  57. plumed/_lib/include/plumed/asmjit/x86compiler.h +322 -0
  58. plumed/_lib/include/plumed/asmjit/x86emitter.h +5149 -0
  59. plumed/_lib/include/plumed/asmjit/x86globals.h +535 -0
  60. plumed/_lib/include/plumed/asmjit/x86inst.h +2547 -0
  61. plumed/_lib/include/plumed/asmjit/x86instimpl_p.h +74 -0
  62. plumed/_lib/include/plumed/asmjit/x86internal_p.h +108 -0
  63. plumed/_lib/include/plumed/asmjit/x86logging_p.h +92 -0
  64. plumed/_lib/include/plumed/asmjit/x86misc.h +417 -0
  65. plumed/_lib/include/plumed/asmjit/x86operand.h +1133 -0
  66. plumed/_lib/include/plumed/asmjit/x86regalloc_p.h +734 -0
  67. plumed/_lib/include/plumed/asmjit/zone.h +1157 -0
  68. plumed/_lib/include/plumed/bias/Bias.h +82 -0
  69. plumed/_lib/include/plumed/bias/ReweightBase.h +58 -0
  70. plumed/_lib/include/plumed/blas/blas.h +253 -0
  71. plumed/_lib/include/plumed/blas/def_external.h +61 -0
  72. plumed/_lib/include/plumed/blas/def_internal.h +97 -0
  73. plumed/_lib/include/plumed/blas/real.h +49 -0
  74. plumed/_lib/include/plumed/cltools/CLTool.h +32 -0
  75. plumed/_lib/include/plumed/clusters/ClusteringBase.h +70 -0
  76. plumed/_lib/include/plumed/colvar/Colvar.h +32 -0
  77. plumed/_lib/include/plumed/colvar/ColvarInput.h +68 -0
  78. plumed/_lib/include/plumed/colvar/ColvarShortcut.h +81 -0
  79. plumed/_lib/include/plumed/colvar/CoordinationBase.h +52 -0
  80. plumed/_lib/include/plumed/colvar/MultiColvarTemplate.h +333 -0
  81. plumed/_lib/include/plumed/colvar/PathMSDBase.h +101 -0
  82. plumed/_lib/include/plumed/colvar/RMSDVector.h +78 -0
  83. plumed/_lib/include/plumed/config/Config.h +118 -0
  84. plumed/_lib/include/plumed/config/version.h +9 -0
  85. plumed/_lib/include/plumed/contour/ContourFindingObject.h +87 -0
  86. plumed/_lib/include/plumed/contour/DistanceFromContourBase.h +82 -0
  87. plumed/_lib/include/plumed/contour/FindContour.h +67 -0
  88. plumed/_lib/include/plumed/core/Action.h +540 -0
  89. plumed/_lib/include/plumed/core/ActionAnyorder.h +48 -0
  90. plumed/_lib/include/plumed/core/ActionAtomistic.h +343 -0
  91. plumed/_lib/include/plumed/core/ActionForInterface.h +99 -0
  92. plumed/_lib/include/plumed/core/ActionPilot.h +57 -0
  93. plumed/_lib/include/plumed/core/ActionRegister.h +124 -0
  94. plumed/_lib/include/plumed/core/ActionSet.h +163 -0
  95. plumed/_lib/include/plumed/core/ActionSetup.h +48 -0
  96. plumed/_lib/include/plumed/core/ActionShortcut.h +73 -0
  97. plumed/_lib/include/plumed/core/ActionToGetData.h +59 -0
  98. plumed/_lib/include/plumed/core/ActionToPutData.h +101 -0
  99. plumed/_lib/include/plumed/core/ActionWithArguments.h +140 -0
  100. plumed/_lib/include/plumed/core/ActionWithMatrix.h +87 -0
  101. plumed/_lib/include/plumed/core/ActionWithValue.h +258 -0
  102. plumed/_lib/include/plumed/core/ActionWithVector.h +94 -0
  103. plumed/_lib/include/plumed/core/ActionWithVirtualAtom.h +123 -0
  104. plumed/_lib/include/plumed/core/CLTool.h +177 -0
  105. plumed/_lib/include/plumed/core/CLToolMain.h +102 -0
  106. plumed/_lib/include/plumed/core/CLToolRegister.h +108 -0
  107. plumed/_lib/include/plumed/core/Colvar.h +115 -0
  108. plumed/_lib/include/plumed/core/DataPassingObject.h +94 -0
  109. plumed/_lib/include/plumed/core/DataPassingTools.h +54 -0
  110. plumed/_lib/include/plumed/core/DomainDecomposition.h +120 -0
  111. plumed/_lib/include/plumed/core/ExchangePatterns.h +47 -0
  112. plumed/_lib/include/plumed/core/FlexibleBin.h +63 -0
  113. plumed/_lib/include/plumed/core/GREX.h +61 -0
  114. plumed/_lib/include/plumed/core/GenericMolInfo.h +89 -0
  115. plumed/_lib/include/plumed/core/Group.h +41 -0
  116. plumed/_lib/include/plumed/core/ModuleMap.h +30 -0
  117. plumed/_lib/include/plumed/core/ParallelTaskManager.h +1023 -0
  118. plumed/_lib/include/plumed/core/PbcAction.h +61 -0
  119. plumed/_lib/include/plumed/core/PlumedMain.h +632 -0
  120. plumed/_lib/include/plumed/core/PlumedMainInitializer.h +118 -0
  121. plumed/_lib/include/plumed/core/RegisterBase.h +340 -0
  122. plumed/_lib/include/plumed/core/TargetDist.h +48 -0
  123. plumed/_lib/include/plumed/core/Value.h +547 -0
  124. plumed/_lib/include/plumed/core/WithCmd.h +93 -0
  125. plumed/_lib/include/plumed/dimred/SMACOF.h +55 -0
  126. plumed/_lib/include/plumed/drr/DRR.h +383 -0
  127. plumed/_lib/include/plumed/drr/colvar_UIestimator.h +777 -0
  128. plumed/_lib/include/plumed/fisst/legendre_rule_fast.h +44 -0
  129. plumed/_lib/include/plumed/function/Custom.h +54 -0
  130. plumed/_lib/include/plumed/function/Function.h +85 -0
  131. plumed/_lib/include/plumed/function/FunctionOfMatrix.h +368 -0
  132. plumed/_lib/include/plumed/function/FunctionOfScalar.h +135 -0
  133. plumed/_lib/include/plumed/function/FunctionOfVector.h +296 -0
  134. plumed/_lib/include/plumed/function/FunctionSetup.h +180 -0
  135. plumed/_lib/include/plumed/function/FunctionShortcut.h +130 -0
  136. plumed/_lib/include/plumed/function/FunctionWithSingleArgument.h +165 -0
  137. plumed/_lib/include/plumed/gridtools/ActionWithGrid.h +43 -0
  138. plumed/_lib/include/plumed/gridtools/EvaluateGridFunction.h +99 -0
  139. plumed/_lib/include/plumed/gridtools/FunctionOfGrid.h +295 -0
  140. plumed/_lib/include/plumed/gridtools/GridCoordinatesObject.h +179 -0
  141. plumed/_lib/include/plumed/gridtools/GridSearch.h +135 -0
  142. plumed/_lib/include/plumed/gridtools/Interpolator.h +45 -0
  143. plumed/_lib/include/plumed/gridtools/KDE.h +455 -0
  144. plumed/_lib/include/plumed/gridtools/RDF.h +40 -0
  145. plumed/_lib/include/plumed/gridtools/SumOfKernels.h +219 -0
  146. plumed/_lib/include/plumed/isdb/MetainferenceBase.h +398 -0
  147. plumed/_lib/include/plumed/lapack/def_external.h +207 -0
  148. plumed/_lib/include/plumed/lapack/def_internal.h +388 -0
  149. plumed/_lib/include/plumed/lapack/lapack.h +899 -0
  150. plumed/_lib/include/plumed/lapack/lapack_limits.h +79 -0
  151. plumed/_lib/include/plumed/lapack/real.h +50 -0
  152. plumed/_lib/include/plumed/lepton/CompiledExpression.h +164 -0
  153. plumed/_lib/include/plumed/lepton/CustomFunction.h +143 -0
  154. plumed/_lib/include/plumed/lepton/Exception.h +93 -0
  155. plumed/_lib/include/plumed/lepton/ExpressionProgram.h +137 -0
  156. plumed/_lib/include/plumed/lepton/ExpressionTreeNode.h +145 -0
  157. plumed/_lib/include/plumed/lepton/Lepton.h +85 -0
  158. plumed/_lib/include/plumed/lepton/MSVC_erfc.h +123 -0
  159. plumed/_lib/include/plumed/lepton/Operation.h +1302 -0
  160. plumed/_lib/include/plumed/lepton/ParsedExpression.h +165 -0
  161. plumed/_lib/include/plumed/lepton/Parser.h +111 -0
  162. plumed/_lib/include/plumed/lepton/windowsIncludes.h +73 -0
  163. plumed/_lib/include/plumed/mapping/Path.h +44 -0
  164. plumed/_lib/include/plumed/mapping/PathProjectionCalculator.h +57 -0
  165. plumed/_lib/include/plumed/matrixtools/MatrixOperationBase.h +54 -0
  166. plumed/_lib/include/plumed/matrixtools/MatrixTimesMatrix.h +309 -0
  167. plumed/_lib/include/plumed/matrixtools/MatrixTimesVectorBase.h +365 -0
  168. plumed/_lib/include/plumed/matrixtools/OuterProduct.h +238 -0
  169. plumed/_lib/include/plumed/maze/Core.h +65 -0
  170. plumed/_lib/include/plumed/maze/Loss.h +86 -0
  171. plumed/_lib/include/plumed/maze/Member.h +66 -0
  172. plumed/_lib/include/plumed/maze/Memetic.h +799 -0
  173. plumed/_lib/include/plumed/maze/Optimizer.h +357 -0
  174. plumed/_lib/include/plumed/maze/Random_MT.h +156 -0
  175. plumed/_lib/include/plumed/maze/Tools.h +183 -0
  176. plumed/_lib/include/plumed/metatomic/vesin.h +188 -0
  177. plumed/_lib/include/plumed/molfile/Gromacs.h +2013 -0
  178. plumed/_lib/include/plumed/molfile/endianswap.h +217 -0
  179. plumed/_lib/include/plumed/molfile/fastio.h +683 -0
  180. plumed/_lib/include/plumed/molfile/largefiles.h +78 -0
  181. plumed/_lib/include/plumed/molfile/libmolfile_plugin.h +77 -0
  182. plumed/_lib/include/plumed/molfile/molfile_plugin.h +1034 -0
  183. plumed/_lib/include/plumed/molfile/periodic_table.h +248 -0
  184. plumed/_lib/include/plumed/molfile/readpdb.h +447 -0
  185. plumed/_lib/include/plumed/molfile/vmdplugin.h +236 -0
  186. plumed/_lib/include/plumed/multicolvar/MultiColvarShortcuts.h +45 -0
  187. plumed/_lib/include/plumed/opes/ExpansionCVs.h +79 -0
  188. plumed/_lib/include/plumed/sasa/Sasa.h +32 -0
  189. plumed/_lib/include/plumed/secondarystructure/SecondaryStructureBase.h +372 -0
  190. plumed/_lib/include/plumed/setup/ActionSetup.h +25 -0
  191. plumed/_lib/include/plumed/small_vector/small_vector.h +6114 -0
  192. plumed/_lib/include/plumed/symfunc/CoordinationNumbers.h +41 -0
  193. plumed/_lib/include/plumed/tools/Angle.h +52 -0
  194. plumed/_lib/include/plumed/tools/AtomDistribution.h +138 -0
  195. plumed/_lib/include/plumed/tools/AtomNumber.h +152 -0
  196. plumed/_lib/include/plumed/tools/BiasRepresentation.h +106 -0
  197. plumed/_lib/include/plumed/tools/BitmaskEnum.h +167 -0
  198. plumed/_lib/include/plumed/tools/Brent1DRootSearch.h +159 -0
  199. plumed/_lib/include/plumed/tools/CheckInRange.h +44 -0
  200. plumed/_lib/include/plumed/tools/Citations.h +74 -0
  201. plumed/_lib/include/plumed/tools/ColvarOutput.h +118 -0
  202. plumed/_lib/include/plumed/tools/Communicator.h +316 -0
  203. plumed/_lib/include/plumed/tools/ConjugateGradient.h +80 -0
  204. plumed/_lib/include/plumed/tools/DLLoader.h +79 -0
  205. plumed/_lib/include/plumed/tools/ERMSD.h +73 -0
  206. plumed/_lib/include/plumed/tools/Exception.h +406 -0
  207. plumed/_lib/include/plumed/tools/File.h +28 -0
  208. plumed/_lib/include/plumed/tools/FileBase.h +153 -0
  209. plumed/_lib/include/plumed/tools/FileTools.h +37 -0
  210. plumed/_lib/include/plumed/tools/ForwardDecl.h +54 -0
  211. plumed/_lib/include/plumed/tools/Grid.h +638 -0
  212. plumed/_lib/include/plumed/tools/HistogramBead.h +136 -0
  213. plumed/_lib/include/plumed/tools/IFile.h +117 -0
  214. plumed/_lib/include/plumed/tools/KernelFunctions.h +113 -0
  215. plumed/_lib/include/plumed/tools/Keywords.h +380 -0
  216. plumed/_lib/include/plumed/tools/LatticeReduction.h +66 -0
  217. plumed/_lib/include/plumed/tools/LeptonCall.h +64 -0
  218. plumed/_lib/include/plumed/tools/LinkCells.h +126 -0
  219. plumed/_lib/include/plumed/tools/Log.h +41 -0
  220. plumed/_lib/include/plumed/tools/LoopUnroller.h +163 -0
  221. plumed/_lib/include/plumed/tools/Matrix.h +721 -0
  222. plumed/_lib/include/plumed/tools/MatrixSquareBracketsAccess.h +138 -0
  223. plumed/_lib/include/plumed/tools/MergeVectorTools.h +153 -0
  224. plumed/_lib/include/plumed/tools/Minimise1DBrent.h +244 -0
  225. plumed/_lib/include/plumed/tools/MinimiseBase.h +120 -0
  226. plumed/_lib/include/plumed/tools/MolDataClass.h +51 -0
  227. plumed/_lib/include/plumed/tools/NeighborList.h +112 -0
  228. plumed/_lib/include/plumed/tools/OFile.h +286 -0
  229. plumed/_lib/include/plumed/tools/OpenACC.h +180 -0
  230. plumed/_lib/include/plumed/tools/OpenMP.h +75 -0
  231. plumed/_lib/include/plumed/tools/PDB.h +154 -0
  232. plumed/_lib/include/plumed/tools/Pbc.h +139 -0
  233. plumed/_lib/include/plumed/tools/PlumedHandle.h +105 -0
  234. plumed/_lib/include/plumed/tools/RMSD.h +493 -0
  235. plumed/_lib/include/plumed/tools/Random.h +80 -0
  236. plumed/_lib/include/plumed/tools/RootFindingBase.h +79 -0
  237. plumed/_lib/include/plumed/tools/Stopwatch.h +475 -0
  238. plumed/_lib/include/plumed/tools/Subprocess.h +142 -0
  239. plumed/_lib/include/plumed/tools/SwitchingFunction.h +208 -0
  240. plumed/_lib/include/plumed/tools/Tensor.h +724 -0
  241. plumed/_lib/include/plumed/tools/TokenizedLine.h +123 -0
  242. plumed/_lib/include/plumed/tools/Tools.h +638 -0
  243. plumed/_lib/include/plumed/tools/Torsion.h +55 -0
  244. plumed/_lib/include/plumed/tools/TrajectoryParser.h +118 -0
  245. plumed/_lib/include/plumed/tools/Tree.h +61 -0
  246. plumed/_lib/include/plumed/tools/TypesafePtr.h +463 -0
  247. plumed/_lib/include/plumed/tools/Units.h +167 -0
  248. plumed/_lib/include/plumed/tools/Vector.h +433 -0
  249. plumed/_lib/include/plumed/tools/View.h +296 -0
  250. plumed/_lib/include/plumed/tools/View2D.h +100 -0
  251. plumed/_lib/include/plumed/tools/h36.h +39 -0
  252. plumed/_lib/include/plumed/vatom/ActionWithVirtualAtom.h +32 -0
  253. plumed/_lib/include/plumed/ves/BasisFunctions.h +380 -0
  254. plumed/_lib/include/plumed/ves/CoeffsBase.h +310 -0
  255. plumed/_lib/include/plumed/ves/CoeffsMatrix.h +220 -0
  256. plumed/_lib/include/plumed/ves/CoeffsVector.h +251 -0
  257. plumed/_lib/include/plumed/ves/FermiSwitchingFunction.h +74 -0
  258. plumed/_lib/include/plumed/ves/GridIntegrationWeights.h +50 -0
  259. plumed/_lib/include/plumed/ves/GridLinearInterpolation.h +81 -0
  260. plumed/_lib/include/plumed/ves/GridProjWeights.h +61 -0
  261. plumed/_lib/include/plumed/ves/LinearBasisSetExpansion.h +303 -0
  262. plumed/_lib/include/plumed/ves/Optimizer.h +444 -0
  263. plumed/_lib/include/plumed/ves/TargetDistModifer.h +53 -0
  264. plumed/_lib/include/plumed/ves/TargetDistribution.h +266 -0
  265. plumed/_lib/include/plumed/ves/VesBias.h +545 -0
  266. plumed/_lib/include/plumed/ves/VesTools.h +142 -0
  267. plumed/_lib/include/plumed/ves/WaveletGrid.h +75 -0
  268. plumed/_lib/include/plumed/volumes/ActionVolume.h +268 -0
  269. plumed/_lib/include/plumed/volumes/VolumeShortcut.h +147 -0
  270. plumed/_lib/include/plumed/wrapper/Plumed.h +5025 -0
  271. plumed/_lib/include/plumed/xdrfile/xdrfile.h +663 -0
  272. plumed/_lib/include/plumed/xdrfile/xdrfile_trr.h +89 -0
  273. plumed/_lib/include/plumed/xdrfile/xdrfile_xtc.h +90 -0
  274. plumed/_lib/lib/PythonCVInterface.so +0 -0
  275. plumed/_lib/lib/libplumed.a +0 -0
  276. plumed/_lib/lib/libplumed.so +0 -0
  277. plumed/_lib/lib/libplumedKernel.so +0 -0
  278. plumed/_lib/lib/libplumedWrapper.a +0 -0
  279. plumed/_lib/lib/pkgconfig/plumed.pc +13 -0
  280. plumed/_lib/lib/pkgconfig/plumedInternals.pc +13 -0
  281. plumed/_lib/lib/pkgconfig/plumedWrapper.pc +13 -0
  282. plumed/_lib/lib/plumed/fortran/plumed.f90 +879 -0
  283. plumed/_lib/lib/plumed/fortran/plumed_f08.f90 +2625 -0
  284. plumed/_lib/lib/plumed/modulefile +69 -0
  285. plumed/_lib/lib/plumed/patches/gromacs-2022.5.config +43 -0
  286. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/CMakeLists.txt +543 -0
  287. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/CMakeLists.txt.preplumed +540 -0
  288. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/expanded.cpp +1628 -0
  289. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/expanded.cpp.preplumed +1590 -0
  290. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/expanded.h +103 -0
  291. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/expanded.h.preplumed +99 -0
  292. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/sim_util.cpp +2527 -0
  293. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdlib/sim_util.cpp.preplumed +2513 -0
  294. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/legacymdrunoptions.cpp +208 -0
  295. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/legacymdrunoptions.cpp.preplumed +175 -0
  296. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/legacymdrunoptions.h +408 -0
  297. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/legacymdrunoptions.h.preplumed +394 -0
  298. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/md.cpp +2348 -0
  299. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/md.cpp.preplumed +2091 -0
  300. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/minimize.cpp +3573 -0
  301. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/minimize.cpp.preplumed +3495 -0
  302. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/replicaexchange.cpp +1506 -0
  303. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/replicaexchange.cpp.preplumed +1402 -0
  304. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/replicaexchange.h +114 -0
  305. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/replicaexchange.h.preplumed +106 -0
  306. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/rerun.cpp +997 -0
  307. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/rerun.cpp.preplumed +906 -0
  308. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/runner.cpp +2780 -0
  309. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/mdrun/runner.cpp.preplumed +2738 -0
  310. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp +224 -0
  311. plumed/_lib/lib/plumed/patches/gromacs-2022.5.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp.preplumed +222 -0
  312. plumed/_lib/lib/plumed/patches/gromacs-2023.5.config +43 -0
  313. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/CMakeLists.txt +549 -0
  314. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/CMakeLists.txt.preplumed +546 -0
  315. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/expanded.cpp +1632 -0
  316. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/expanded.cpp.preplumed +1594 -0
  317. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/expanded.h +104 -0
  318. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/expanded.h.preplumed +100 -0
  319. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/sim_util.cpp +2624 -0
  320. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdlib/sim_util.cpp.preplumed +2610 -0
  321. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/legacymdrunoptions.cpp +208 -0
  322. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/legacymdrunoptions.cpp.preplumed +175 -0
  323. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/legacymdrunoptions.h +409 -0
  324. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/legacymdrunoptions.h.preplumed +395 -0
  325. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/md.cpp +2419 -0
  326. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/md.cpp.preplumed +2164 -0
  327. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/minimize.cpp +3546 -0
  328. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/minimize.cpp.preplumed +3468 -0
  329. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/replicaexchange.cpp +1513 -0
  330. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/replicaexchange.cpp.preplumed +1409 -0
  331. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/replicaexchange.h +114 -0
  332. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/replicaexchange.h.preplumed +106 -0
  333. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/rerun.cpp +991 -0
  334. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/rerun.cpp.preplumed +900 -0
  335. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/runner.cpp +2895 -0
  336. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/mdrun/runner.cpp.preplumed +2849 -0
  337. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp +224 -0
  338. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp.preplumed +222 -0
  339. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/taskassignment/decidegpuusage.cpp +886 -0
  340. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/taskassignment/decidegpuusage.cpp.preplumed +880 -0
  341. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/taskassignment/include/gromacs/taskassignment/decidegpuusage.h +347 -0
  342. plumed/_lib/lib/plumed/patches/gromacs-2023.5.diff/src/gromacs/taskassignment/include/gromacs/taskassignment/decidegpuusage.h.preplumed +345 -0
  343. plumed/_lib/lib/plumed/patches/gromacs-2024.3.config +43 -0
  344. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/CMakeLists.txt +575 -0
  345. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/CMakeLists.txt.preplumed +572 -0
  346. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/expanded.cpp +1632 -0
  347. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/expanded.cpp.preplumed +1594 -0
  348. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/expanded.h +104 -0
  349. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/expanded.h.preplumed +100 -0
  350. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/sim_util.cpp +2564 -0
  351. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdlib/sim_util.cpp.preplumed +2550 -0
  352. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/legacymdrunoptions.cpp +208 -0
  353. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/legacymdrunoptions.cpp.preplumed +175 -0
  354. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/legacymdrunoptions.h +410 -0
  355. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/legacymdrunoptions.h.preplumed +396 -0
  356. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/md.cpp +2435 -0
  357. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/md.cpp.preplumed +2187 -0
  358. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/minimize.cpp +3592 -0
  359. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/minimize.cpp.preplumed +3514 -0
  360. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/replicaexchange.cpp +1513 -0
  361. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/replicaexchange.cpp.preplumed +1409 -0
  362. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/replicaexchange.h +114 -0
  363. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/replicaexchange.h.preplumed +106 -0
  364. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/rerun.cpp +958 -0
  365. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/rerun.cpp.preplumed +929 -0
  366. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/runner.cpp +2987 -0
  367. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/mdrun/runner.cpp.preplumed +2941 -0
  368. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp +224 -0
  369. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/modularsimulator/expandedensembleelement.cpp.preplumed +222 -0
  370. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/taskassignment/decidegpuusage.cpp +904 -0
  371. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/taskassignment/decidegpuusage.cpp.preplumed +898 -0
  372. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/taskassignment/include/gromacs/taskassignment/decidegpuusage.h +353 -0
  373. plumed/_lib/lib/plumed/patches/gromacs-2024.3.diff/src/gromacs/taskassignment/include/gromacs/taskassignment/decidegpuusage.h.preplumed +351 -0
  374. plumed/_lib/lib/plumed/patches/gromacs-2025.0.config +39 -0
  375. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/cmake/gmxManagePlumed.cmake +82 -0
  376. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/cmake/gmxManagePlumed.cmake.preplumed +82 -0
  377. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedMDModule.cpp +162 -0
  378. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedMDModule.cpp.preplumed +154 -0
  379. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedOptions.cpp +107 -0
  380. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedOptions.cpp.preplumed +99 -0
  381. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedOptions.h +120 -0
  382. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedOptions.h.preplumed +111 -0
  383. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedforceprovider.cpp +215 -0
  384. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedforceprovider.cpp.preplumed +197 -0
  385. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedforceprovider.h +87 -0
  386. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/applied_forces/plumed/plumedforceprovider.h.preplumed +86 -0
  387. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/mdrun/runner.cpp +2971 -0
  388. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/mdrun/runner.cpp.preplumed +2970 -0
  389. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/mdrunutility/mdmodulesnotifiers.h +430 -0
  390. plumed/_lib/lib/plumed/patches/gromacs-2025.0.diff/src/gromacs/mdrunutility/mdmodulesnotifiers.h.preplumed +429 -0
  391. plumed/_lib/lib/plumed/patches/namd-2.12.config +30 -0
  392. plumed/_lib/lib/plumed/patches/namd-2.12.diff +267 -0
  393. plumed/_lib/lib/plumed/patches/namd-2.13.config +30 -0
  394. plumed/_lib/lib/plumed/patches/namd-2.13.diff +267 -0
  395. plumed/_lib/lib/plumed/patches/namd-2.14.config +30 -0
  396. plumed/_lib/lib/plumed/patches/namd-2.14.diff +268 -0
  397. plumed/_lib/lib/plumed/patches/patch.sh +500 -0
  398. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.config +25 -0
  399. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/forces.f90 +368 -0
  400. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/forces.f90.preplumed +366 -0
  401. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/plugin_forces.f90 +71 -0
  402. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/plugin_forces.f90.preplumed +24 -0
  403. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/plugin_initialization.f90 +62 -0
  404. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/plugin_initialization.f90.preplumed +21 -0
  405. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/pwscf.f90 +189 -0
  406. plumed/_lib/lib/plumed/patches/qespresso-5.0.2.diff/PW/src/pwscf.f90.preplumed +185 -0
  407. plumed/_lib/lib/plumed/patches/qespresso-6.2.config +26 -0
  408. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/forces.f90 +422 -0
  409. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/forces.f90.preplumed +420 -0
  410. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/plugin_ext_forces.f90 +70 -0
  411. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/plugin_ext_forces.f90.preplumed +23 -0
  412. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/plugin_initialization.f90 +62 -0
  413. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/plugin_initialization.f90.preplumed +21 -0
  414. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/run_pwscf.f90 +233 -0
  415. plumed/_lib/lib/plumed/patches/qespresso-6.2.diff/PW/src/run_pwscf.f90.preplumed +230 -0
  416. plumed/_lib/lib/plumed/patches/qespresso-7.0.config +28 -0
  417. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/Modules/Makefile +175 -0
  418. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/Modules/Makefile.preplumed +171 -0
  419. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/forces.f90 +486 -0
  420. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/forces.f90.preplumed +484 -0
  421. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/plugin_ext_forces.f90 +74 -0
  422. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/plugin_ext_forces.f90.preplumed +23 -0
  423. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/plugin_initialization.f90 +64 -0
  424. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/plugin_initialization.f90.preplumed +21 -0
  425. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/run_pwscf.f90 +532 -0
  426. plumed/_lib/lib/plumed/patches/qespresso-7.0.diff/PW/src/run_pwscf.f90.preplumed +518 -0
  427. plumed/_lib/lib/plumed/patches/qespresso-7.2.config +28 -0
  428. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/Modules/Makefile +249 -0
  429. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/Modules/Makefile.preplumed +244 -0
  430. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/forces.f90 +532 -0
  431. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/forces.f90.preplumed +535 -0
  432. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/plugin_ext_forces.f90 +74 -0
  433. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/plugin_ext_forces.f90.preplumed +23 -0
  434. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/plugin_initialization.f90 +64 -0
  435. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/plugin_initialization.f90.preplumed +21 -0
  436. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/run_pwscf.f90 +569 -0
  437. plumed/_lib/lib/plumed/patches/qespresso-7.2.diff/PW/src/run_pwscf.f90.preplumed +560 -0
  438. plumed/_lib/lib/plumed/plumed-config +9 -0
  439. plumed/_lib/lib/plumed/plumed-mklib +9 -0
  440. plumed/_lib/lib/plumed/plumed-newcv +9 -0
  441. plumed/_lib/lib/plumed/plumed-partial_tempering +9 -0
  442. plumed/_lib/lib/plumed/plumed-patch +9 -0
  443. plumed/_lib/lib/plumed/plumed-runtime +0 -0
  444. plumed/_lib/lib/plumed/plumed-selector +9 -0
  445. plumed/_lib/lib/plumed/plumed-vim2html +9 -0
  446. plumed/_lib/lib/plumed/scripts/config.sh +126 -0
  447. plumed/_lib/lib/plumed/scripts/mklib.sh +175 -0
  448. plumed/_lib/lib/plumed/scripts/newcv.sh +26 -0
  449. plumed/_lib/lib/plumed/scripts/partial_tempering.sh +319 -0
  450. plumed/_lib/lib/plumed/scripts/patch.sh +4 -0
  451. plumed/_lib/lib/plumed/scripts/selector.sh +234 -0
  452. plumed/_lib/lib/plumed/scripts/vim2html.sh +190 -0
  453. plumed/_lib/lib/plumed/src/colvar/Template.cpp +116 -0
  454. plumed/_lib/lib/plumed/src/config/compile_options.sh +3 -0
  455. plumed/_lib/lib/plumed/src/config/config.txt +179 -0
  456. plumed/_lib/lib/plumed/src/lib/Plumed.cmake +8 -0
  457. plumed/_lib/lib/plumed/src/lib/Plumed.cmake.runtime +5 -0
  458. plumed/_lib/lib/plumed/src/lib/Plumed.cmake.shared +5 -0
  459. plumed/_lib/lib/plumed/src/lib/Plumed.cmake.static +5 -0
  460. plumed/_lib/lib/plumed/src/lib/Plumed.inc +8 -0
  461. plumed/_lib/lib/plumed/src/lib/Plumed.inc.runtime +5 -0
  462. plumed/_lib/lib/plumed/src/lib/Plumed.inc.shared +5 -0
  463. plumed/_lib/lib/plumed/src/lib/Plumed.inc.static +5 -0
  464. plumed/_lib/lib/plumed/vim/scripts.vim +6 -0
  465. plumed/_plumed_core.cpython-311-aarch64-linux-gnu.so +0 -0
  466. plumed/_plumed_core.cpython-312-aarch64-linux-gnu.so +0 -0
  467. plumed/_plumed_core.cpython-313-aarch64-linux-gnu.so +0 -0
  468. plumed/_plumed_core.cpython-314-aarch64-linux-gnu.so +0 -0
  469. plumed/_plumed_core.cpython-314t-aarch64-linux-gnu.so +0 -0
  470. plumedCommunications.cpython-311-aarch64-linux-gnu.so +0 -0
  471. plumedCommunications.cpython-312-aarch64-linux-gnu.so +0 -0
  472. plumedCommunications.cpython-313-aarch64-linux-gnu.so +0 -0
  473. plumedCommunications.cpython-314-aarch64-linux-gnu.so +0 -0
  474. plumedCommunications.cpython-314t-aarch64-linux-gnu.so +0 -0
  475. plumedCommunications.pyi +431 -0
@@ -0,0 +1,2013 @@
1
+ /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
+ University of Illinois Open Source License
3
+ Copyright 2003 Theoretical and Computational Biophysics Group,
4
+ All rights reserved.
5
+
6
+ Developed by: Theoretical and Computational Biophysics Group
7
+ University of Illinois at Urbana-Champaign
8
+ http://www.ks.uiuc.edu/
9
+
10
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
11
+ this software and associated documentation files (the Software), to deal with
12
+ the Software without restriction, including without limitation the rights to
13
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
14
+ of the Software, and to permit persons to whom the Software is furnished to
15
+ do so, subject to the following conditions:
16
+
17
+ Redistributions of source code must retain the above copyright notice,
18
+ this list of conditions and the following disclaimers.
19
+
20
+ Redistributions in binary form must reproduce the above copyright notice,
21
+ this list of conditions and the following disclaimers in the documentation
22
+ and/or other materials provided with the distribution.
23
+
24
+ Neither the names of Theoretical and Computational Biophysics Group,
25
+ University of Illinois at Urbana-Champaign, nor the names of its contributors
26
+ may be used to endorse or promote products derived from this Software without
27
+ specific prior written permission.
28
+
29
+ THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
32
+ THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
33
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
34
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35
+ OTHER DEALINGS WITH THE SOFTWARE.
36
+ +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
37
+ #ifndef __PLUMED_molfile_Gromacs_h
38
+ #define __PLUMED_molfile_Gromacs_h
39
+ /***************************************************************************
40
+ *cr
41
+ *cr (C) Copyright 1995-2016 The Board of Trustees of the
42
+ *cr University of Illinois
43
+ *cr All Rights Reserved
44
+ *cr
45
+ ***************************************************************************/
46
+ /***************************************************************************
47
+ * RCS INFORMATION:
48
+ * $RCSfile: Gromacs.h,v $
49
+ * $Author: johns $ $Locker: $ $State: Exp $
50
+ * $Revision: 1.36 $ $Date: 2020/01/09 16:21:28 $
51
+ ***************************************************************************/
52
+
53
+ /*
54
+ * GROMACS file format reader for VMD
55
+ *
56
+ * This code provides a high level I/O library for reading
57
+ * and writing the following file formats:
58
+ * gro GROMACS format or trajectory
59
+ * g96 GROMOS-96 format or trajectory
60
+ * trj Trajectory - x, v and f (binary, full precision)
61
+ * trr Trajectory - x, v and f (binary, full precision, portable)
62
+ * xtc Trajectory - x only (compressed, portable, any precision)
63
+ * top
64
+ * Currently supported: gro trj trr g96 [xtc]
65
+ *
66
+ * TODO list
67
+ * o velocities are ignored because VMD doesn't use them, but some other
68
+ * program might ...
69
+ * o gro_rec() assumes positions in .gro files are nanometers and
70
+ * converts to angstroms, whereas they really could be any unit
71
+ */
72
+
73
+ #ifndef GROMACS_H
74
+ #define GROMACS_H
75
+
76
+ #include <math.h>
77
+ #include <stdio.h>
78
+ #include <stdlib.h>
79
+ #include <string.h>
80
+ #include <ctype.h>
81
+
82
+ #if defined(_AIX)
83
+ #include <strings.h>
84
+ #endif
85
+
86
+ #include "endianswap.h"
87
+
88
+ namespace PLMD{
89
+ namespace molfile{
90
+
91
+ #if defined(WIN32) || defined(WIN64)
92
+ #define strcasecmp stricmp
93
+ #endif
94
+
95
+ #ifndef M_PI_2
96
+ #define M_PI_2 1.57079632679489661922
97
+ #endif
98
+
99
+ // Error codes for mdio_errno
100
+ #define MDIO_SUCCESS 0
101
+ #define MDIO_BADFORMAT 1
102
+ #define MDIO_EOF 2
103
+ #define MDIO_BADPARAMS 3
104
+ #define MDIO_IOERROR 4
105
+ #define MDIO_BADPRECISION 5
106
+ #define MDIO_BADMALLOC 6
107
+ #define MDIO_CANTOPEN 7
108
+ #define MDIO_BADEXTENSION 8
109
+ #define MDIO_UNKNOWNFMT 9
110
+ #define MDIO_CANTCLOSE 10
111
+ #define MDIO_WRONGFORMAT 11
112
+ #define MDIO_SIZEERROR 12
113
+ #define MDIO_UNKNOWNERROR 1000
114
+
115
+ #define MDIO_READ 0
116
+ #define MDIO_WRITE 1
117
+
118
+ #define MDIO_MAX_ERRVAL 11
119
+
120
+ // Format extensions
121
+ const char *mdio_fmtexts[] = {
122
+ "",
123
+ ".gro",
124
+ ".trr",
125
+ ".g96",
126
+ ".trj",
127
+ ".xtc",
128
+ NULL
129
+ };
130
+
131
+
132
+ static int mdio_errcode; // Last error code
133
+
134
+ #define TRX_MAGIC 1993 // Magic number for .trX files
135
+ #define XTC_MAGIC 1995 // Magic number for .xtc files
136
+ #define MAX_GRO_LINE 500 // Maximum line length of .gro files
137
+ #define MAX_G96_LINE 500 // Maximum line length of .g96 files
138
+ #define MAX_TRX_TITLE 80 // Maximum length of a title in .trX
139
+ #define MAX_MDIO_TITLE 80 // Maximum supported title length
140
+ #define ANGS_PER_NM 10 // Unit conversion factor
141
+ #define ANGS2_PER_NM2 100 // Unit conversion factor
142
+
143
+
144
+ // All the supported file types and their respective extensions
145
+ #define MDFMT_GRO 1
146
+ #define MDFMT_TRR 2
147
+ #define MDFMT_G96 3
148
+ #define MDFMT_TRJ 4
149
+ #define MDFMT_XTC 5
150
+
151
+
152
+ // A structure to hold .trX file format header information. This
153
+ // is an optional member of the md_file structure that is used
154
+ // when .trX files are being dealt with.
155
+ typedef struct {
156
+ int version; // File version number
157
+ char title[MAX_TRX_TITLE + 1]; // File title
158
+ int ir_size;
159
+ int e_size;
160
+ int box_size;
161
+ int vir_size;
162
+ int pres_size;
163
+ int top_size;
164
+ int sym_size;
165
+ int x_size; // Positions of atoms
166
+ int v_size; // Velocities of atoms
167
+ int f_size;
168
+ int natoms; // Number of atoms in the system
169
+ int step;
170
+ int nre;
171
+ float t;
172
+ float lambda;
173
+ } trx_hdr;
174
+
175
+
176
+ // A generic i/o structure that contains information about the
177
+ // file itself and the input/output state
178
+ typedef struct {
179
+ FILE * f; // Pointer to the file
180
+ int fmt; // The file format
181
+ int prec; // Real number precision
182
+ int rev; // Reverse endiannism?
183
+ trx_hdr * trx; // Trx files require a great deal more
184
+ // header data to be stored.
185
+ } md_file;
186
+
187
+
188
+ // A format-independent structure to hold header data from files
189
+ typedef struct {
190
+ char title[MAX_MDIO_TITLE + 1];
191
+ int natoms;
192
+ float timeval;
193
+ } md_header;
194
+
195
+
196
+ // A format-independent structure to hold unit cell data
197
+ typedef struct {
198
+ float A, B, C, alpha, beta, gamma;
199
+ } md_box;
200
+
201
+
202
+ // Timestep information
203
+ typedef struct {
204
+ float *pos; // Position array (3 * natoms)
205
+ //float *vel; // Velocity array ** (VMD doesn't use this) **
206
+ //float *f; // Force array ** (VMD doesn't use this) **
207
+ //float *box; // Computational box ** (VMD doesn't use this) **
208
+ int natoms; // Number of atoms
209
+ int step; // Simulation step
210
+ float time; // Time of simulation
211
+ md_box *box;
212
+ } md_ts;
213
+
214
+
215
+ // Atom information
216
+ typedef struct {
217
+ char resid[7]; // Residue index number
218
+ char resname[7]; // Residue name
219
+ int atomnum; // Atom index number
220
+ char atomname[7]; // Atom name
221
+ float pos[3]; // Position array (3 * natoms)
222
+ //float vel[3]; // Velocity array ** (VMD doesn't use this) **
223
+ } md_atom;
224
+
225
+
226
+ // Open a molecular dynamics file. The second parameter specifies
227
+ // the format of the file. If it is zero, the format is determined
228
+ // from the file extension. the third argument (if given) decides
229
+ // whether to read (==0) or to write (!= 0).
230
+ // using a default argument set to read for backward compatibility.
231
+ static md_file *mdio_open(const char *, const int, const int=MDIO_READ);
232
+
233
+ // Closes a molecular dynamics file.
234
+ static int mdio_close(md_file *);
235
+
236
+
237
+ // Format-independent file I/O routines
238
+ static int mdio_header(md_file *, md_header *);
239
+ static int mdio_timestep(md_file *, md_ts *);
240
+
241
+
242
+ // .gro file functions
243
+ static int gro_header(md_file *, char *, int, float *, int *, int = 1);
244
+ static int gro_rec(md_file *, md_atom *);
245
+ static int gro_timestep(md_file *, md_ts *);
246
+
247
+
248
+ // .trX file functions
249
+ static int trx_header(md_file *, int = 0);
250
+ static int trx_int(md_file *, int *);
251
+ static int trx_real(md_file *, float *);
252
+
253
+ static int trx_rvector(md_file *, float *);
254
+ static int trx_string(md_file *, char *, int);
255
+ static int trx_timestep(md_file *, md_ts *);
256
+
257
+ // .g96 file functions
258
+ static int g96_header(md_file *, char *, int, float *);
259
+ static int g96_timestep(md_file *, md_ts *);
260
+ static int g96_rec(md_file *, md_atom *);
261
+ static int g96_countatoms(md_file *);
262
+
263
+
264
+ // .xtc file functions
265
+ static int xtc_int(md_file *, int *);
266
+ static int xtc_float(md_file *, float *);
267
+ /*
268
+ static int xtc_receivebits(int *, int);
269
+ static void xtc_receiveints(int *, int, int, const unsigned *, int *);
270
+ */
271
+ static int xtc_timestep(md_file *, md_ts *);
272
+ static int xtc_3dfcoord(md_file *, float *, int *, float *);
273
+
274
+
275
+ // Error reporting functions
276
+ static int mdio_errno(void);
277
+ static const char *mdio_errmsg(int);
278
+ static int mdio_seterror(int);
279
+
280
+
281
+ // Miscellaneous functions
282
+ static int strip_white(char *);
283
+ static int mdio_readline(md_file *, char *, int, int = 1);
284
+ static int mdio_tsfree(md_ts *, int = 0);
285
+ static int mdio_readbox(md_box *, float *, float *, float *);
286
+
287
+
288
+
289
+ static int xtc_receivebits(int *, int);
290
+
291
+ // Error descriptions for mdio_errno
292
+ static const char *mdio_errdescs[] = {
293
+ "no error",
294
+ "file does not match format",
295
+ "unexpected end-of-file reached",
296
+ "function called with bad parameters",
297
+ "file i/o error",
298
+ "unsupported precision",
299
+ "out of memory",
300
+ "cannot open file",
301
+ "bad file extension",
302
+ "unknown file format",
303
+ "cannot close file",
304
+ "wrong file format for this function",
305
+ "binary i/o error: sizeof(int) != 4",
306
+ NULL
307
+ };
308
+
309
+ /*! \fn static inline bool host_is_little_endian(void)
310
+ * detect endiannes of host machine. returns true on little endian machines. */
311
+ static inline int host_is_little_endian(void)
312
+ {
313
+ const union { unsigned char c[4]; unsigned int i; }
314
+ fixed = { { 0x10 , 0x20 , 0x40 , 0x80 } };
315
+ const unsigned int i = 0x80402010U;
316
+
317
+ if (fixed.i == i) {
318
+ return 1;
319
+ }
320
+ return 0;
321
+ }
322
+
323
+
324
+
325
+ // Open a molecular dynamics file. The second parameter specifies
326
+ // the format of the file. If it is zero, the format is determined
327
+ // from the file extension.
328
+ md_file *mdio_open(const char *fn, const int fmt, const int rw) {
329
+ md_file *mf;
330
+
331
+ if (!fn) {
332
+ mdio_seterror(MDIO_BADPARAMS);
333
+ return NULL;
334
+ }
335
+
336
+ // Allocate memory
337
+ mf = (md_file *) malloc(sizeof(md_file));
338
+ if (!mf) {
339
+ mdio_seterror(MDIO_BADMALLOC);
340
+ return NULL;
341
+ }
342
+
343
+ // Zero out the structure
344
+ memset(mf, 0, sizeof(md_file));
345
+
346
+ // Determine the file type from the extension
347
+ if (!fmt) {
348
+ char *p;
349
+ int n;
350
+
351
+ // Seek to the extension part of the filename
352
+ for (p = (char *) &fn[strlen(fn) - 1]; *p != '.' && p > fn; p--);
353
+ if (p == fn) {
354
+ free(mf);
355
+ mdio_seterror(MDIO_BADEXTENSION);
356
+ return NULL;
357
+ }
358
+
359
+ // Check the extension against known extensions
360
+ for (n = 1; mdio_fmtexts[n]; n++)
361
+ if (!strcasecmp(p, mdio_fmtexts[n])) break;
362
+
363
+ // If !mdio_fmtexts[n], we failed (unknown ext)
364
+ if (!mdio_fmtexts[n]) {
365
+ free(mf);
366
+ mdio_seterror(MDIO_UNKNOWNFMT);
367
+ return NULL;
368
+ }
369
+
370
+ // All set
371
+ mf->fmt = n;
372
+ }
373
+ else {
374
+ mf->fmt = fmt;
375
+ }
376
+
377
+ // Differentiate between binary and ascii files. Also,
378
+ // .trX files need a header information structure allocated.
379
+ switch (mf->fmt) {
380
+ case MDFMT_GRO:
381
+ case MDFMT_G96: /* fallthrough */
382
+ if (rw)
383
+ mf->f = fopen(fn, "wt");
384
+ else
385
+ mf->f = fopen(fn, "rt");
386
+
387
+ break;
388
+ case MDFMT_TRR:
389
+ case MDFMT_TRJ: /* fallthrough */
390
+ // Allocate the trx header data struct
391
+ mf->trx = (trx_hdr *) malloc(sizeof(trx_hdr));
392
+ if (!mf->trx) {
393
+ free(mf);
394
+ mdio_seterror(MDIO_BADMALLOC);
395
+ return NULL;
396
+ }
397
+ memset(mf->trx, 0, sizeof(trx_hdr));
398
+ case MDFMT_XTC: /* fallthrough */
399
+ // Finally, open the file
400
+ if (rw)
401
+ mf->f = fopen(fn, "wb");
402
+ else
403
+ mf->f = fopen(fn, "rb");
404
+
405
+ break;
406
+ default:
407
+ free(mf);
408
+ mdio_seterror(MDIO_UNKNOWNFMT);
409
+ return NULL;
410
+ }
411
+
412
+ // Check for opening error
413
+ if (!mf->f) {
414
+ if (mf->trx) free(mf->trx);
415
+ free(mf);
416
+ mdio_seterror(MDIO_CANTOPEN);
417
+ return NULL;
418
+ }
419
+
420
+ // File is opened, we're all set!
421
+ mdio_seterror(MDIO_SUCCESS);
422
+ return mf;
423
+ }
424
+
425
+
426
+ // Closes a molecular dynamics file.
427
+ static int mdio_close(md_file *mf) {
428
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
429
+
430
+ if (fclose(mf->f) == EOF) return mdio_seterror(MDIO_CANTCLOSE);
431
+
432
+ // Free the dynamically allocated memory
433
+ if (mf->trx) free(mf->trx);
434
+ free(mf);
435
+ return mdio_seterror(MDIO_SUCCESS);
436
+ }
437
+
438
+
439
+ // Returns the last error code reported by any of the mdio functions
440
+ static int mdio_errno(void) {
441
+ return mdio_errcode;
442
+ }
443
+
444
+
445
+ // Returns a textual message regarding an mdio error code
446
+ static const char *mdio_errmsg(int n) {
447
+ if (n < 0 || n > MDIO_MAX_ERRVAL) return (char *) "unknown error";
448
+ else return mdio_errdescs[n];
449
+ }
450
+
451
+
452
+ // Sets the error code and returns an appropriate return value
453
+ // for the calling function to return to its parent
454
+ static int mdio_seterror(int code) {
455
+ mdio_errcode = code;
456
+ return code ? -1 : 0;
457
+ }
458
+
459
+
460
+ // Reads a line from the text file, strips leading/trailing whitespace
461
+ // and newline, checks for errors, and returns the number of characters
462
+ // in the string on success or -1 on error.
463
+ static int mdio_readline(md_file *mf, char *buf, int n, int strip) {
464
+ if (!buf || n < 1 || !mf) return mdio_seterror(MDIO_BADPARAMS);
465
+
466
+ // Read the line
467
+ fgets(buf, n, mf->f);
468
+
469
+ // End of file reached?
470
+ if (feof(mf->f)) return mdio_seterror(MDIO_EOF);
471
+
472
+ // File I/O error?
473
+ if (ferror(mf->f)) return mdio_seterror(MDIO_IOERROR);
474
+
475
+ // comment line?
476
+ if (buf[0] == '#') return mdio_readline(mf,buf,n,strip);
477
+
478
+ // Strip whitespace
479
+ if (strip) strip_white(buf);
480
+
481
+ return strlen(buf);
482
+ }
483
+
484
+
485
+ // Strips leading and trailing whitespace from a string. Tabs,
486
+ // spaces, newlines and carriage returns are stripped. Example:
487
+ // "\n hello\t \r" becomes "hello".
488
+ static int strip_white(char *buf) {
489
+ int i, j, k;
490
+
491
+ // Protect against NULL pointer
492
+ if (!buf) return -1;
493
+ if (!strlen(buf)) return -1;
494
+
495
+ // Kill trailing whitespace first
496
+ for (i = strlen(buf) - 1;
497
+ buf[i] == ' ' || buf[i] == '\t' ||
498
+ buf[i] == '\n' || buf[i] == '\r';
499
+ i--)
500
+ buf[i] = 0;
501
+
502
+ // Skip past leading whitespace
503
+ for (i = 0; buf[i] == ' ' || buf[i] == '\t' ||
504
+ buf[i] == '\n' || buf[i] == '\r'; i++);
505
+ if (i) {
506
+ k = 0;
507
+ for (j = i; buf[j]; j++)
508
+ buf[k++] = buf[j];
509
+ buf[k] = 0;
510
+ }
511
+
512
+ return strlen(buf);
513
+ }
514
+
515
+
516
+ // Frees the memory allocated in a ts structure. The holderror
517
+ // parameter defaults to zero. Programs that are calling this
518
+ // function because of an error reported by another function should
519
+ // set holderror so that mdio_tsfree() does not overwrite the error
520
+ // code with mdio_seterror().
521
+ static int mdio_tsfree(md_ts *ts, int holderror) {
522
+ if (!ts) {
523
+ if (holderror) return -1;
524
+ else return mdio_seterror(MDIO_BADPARAMS);
525
+ }
526
+
527
+ if (ts->pos && ts->natoms > 0) free(ts->pos);
528
+
529
+ if (ts->box) free(ts->box);
530
+
531
+ if (holderror) return -1;
532
+ else return mdio_seterror(MDIO_SUCCESS);
533
+ }
534
+
535
+
536
+ // Converts box basis vectors to A, B, C, alpha, beta, and gamma.
537
+ // Stores values in md_box struct, which should be allocated before calling
538
+ // this function.
539
+ static int mdio_readbox(md_box *box, float *x, float *y, float *z) {
540
+ float A, B, C;
541
+
542
+ if (!box) {
543
+ return mdio_seterror(MDIO_BADPARAMS);
544
+ }
545
+
546
+ // A, B, C are the lengths of the x, y, z vectors, respectively
547
+ A = sqrt( x[0]*x[0] + x[1]*x[1] + x[2]*x[2] ) * ANGS_PER_NM;
548
+ B = sqrt( y[0]*y[0] + y[1]*y[1] + y[2]*y[2] ) * ANGS_PER_NM;
549
+ C = sqrt( z[0]*z[0] + z[1]*z[1] + z[2]*z[2] ) * ANGS_PER_NM;
550
+ if ((A<=0) || (B<=0) || (C<=0)) {
551
+ /* Use zero-length box size and set angles to 90. */
552
+ box->A = box->B = box->C = 0;
553
+ box->alpha = box->beta = box->gamma = 90;
554
+ } else {
555
+ box->A = A;
556
+ box->B = B;
557
+ box->C = C;
558
+
559
+ // gamma, beta, alpha are the angles between the x & y, x & z, y & z
560
+ // vectors, respectively
561
+ box->gamma = acos( (x[0]*y[0]+x[1]*y[1]+x[2]*y[2])*ANGS2_PER_NM2/(A*B) ) * 90.0/M_PI_2;
562
+ box->beta = acos( (x[0]*z[0]+x[1]*z[1]+x[2]*z[2])*ANGS2_PER_NM2/(A*C) ) * 90.0/M_PI_2;
563
+ box->alpha = acos( (y[0]*z[0]+y[1]*z[1]+y[2]*z[2])*ANGS2_PER_NM2/(B*C) ) * 90.0/M_PI_2;
564
+ }
565
+ return mdio_seterror(MDIO_SUCCESS);
566
+ }
567
+
568
+
569
+ // Reads the header of a file (format independent)
570
+ static int mdio_header(md_file *mf, md_header *mdh) {
571
+ int n;
572
+ if (!mf || !mdh) return mdio_seterror(MDIO_BADPARAMS);
573
+ if (!mf->f) return mdio_seterror(MDIO_BADPARAMS);
574
+
575
+ switch (mf->fmt) {
576
+ case MDFMT_GRO:
577
+ if (gro_header(mf, mdh->title, MAX_MDIO_TITLE,
578
+ &mdh->timeval, &mdh->natoms, 1) < 0)
579
+ return -1;
580
+ return 0;
581
+
582
+ case MDFMT_TRR:
583
+ case MDFMT_TRJ: /* fallthrough */
584
+ if (trx_header(mf, 1) < 0) return -1;
585
+ mdh->natoms = mf->trx->natoms;
586
+ mdh->timeval = (float) mf->trx->t;
587
+ strncpy(mdh->title, mf->trx->title, MAX_MDIO_TITLE);
588
+ return 0;
589
+
590
+ case MDFMT_G96:
591
+ if (g96_header(mf, mdh->title, MAX_MDIO_TITLE,
592
+ &mdh->timeval) < 0) return -1;
593
+ mdh->natoms = -1;
594
+ return 0;
595
+
596
+ case MDFMT_XTC:
597
+ memset(mdh, 0, sizeof(md_header));
598
+ // Check magic number
599
+ if (xtc_int(mf, &n) < 0) return -1;
600
+ if (n != XTC_MAGIC) return mdio_seterror(MDIO_BADFORMAT);
601
+
602
+ // Get number of atoms
603
+ if (xtc_int(mf, &n) < 0) return -1;
604
+ mdh->natoms = n;
605
+ rewind(mf->f);
606
+ return 0;
607
+
608
+ default:
609
+ return mdio_seterror(MDIO_UNKNOWNFMT);
610
+ }
611
+ }
612
+
613
+
614
+ // Reads in a timestep from a file (format independent)
615
+ static int mdio_timestep(md_file *mf, md_ts *ts) {
616
+ if (!mf || !ts) return mdio_seterror(MDIO_BADPARAMS);
617
+ if (!mf->f) return mdio_seterror(MDIO_BADPARAMS);
618
+
619
+ switch (mf->fmt) {
620
+ case MDFMT_GRO:
621
+ return gro_timestep(mf, ts);
622
+
623
+ case MDFMT_TRR:
624
+ case MDFMT_TRJ: /* fallthrough */
625
+ return trx_timestep(mf, ts);
626
+
627
+ case MDFMT_G96:
628
+ return g96_timestep(mf, ts);
629
+
630
+ case MDFMT_XTC:
631
+ return xtc_timestep(mf, ts);
632
+
633
+ default:
634
+ return mdio_seterror(MDIO_UNKNOWNFMT);
635
+ }
636
+ }
637
+
638
+
639
+
640
+ static int g96_header(md_file *mf, char *title, int titlelen, float *timeval) {
641
+ char buf[MAX_G96_LINE + 1];
642
+ char *p;
643
+
644
+ // Check parameters
645
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
646
+
647
+ // The header consists of blocks. The title block
648
+ // is mandatory, and a TIMESTEP block is optional.
649
+ // Example:
650
+ //
651
+ // TITLE
652
+ // Generated by trjconv : t= 90.00000
653
+ // more title info
654
+ // .
655
+ // .
656
+ // .
657
+ // END
658
+ // .
659
+ // .
660
+ // .
661
+
662
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
663
+ if (strcasecmp(buf, "TITLE")) return mdio_seterror(MDIO_BADFORMAT);
664
+
665
+ // Read in the title itself
666
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
667
+
668
+ // The timevalue can be included in the title string
669
+ // after a "t=" prefix.
670
+ if ((p = (char *) strstr(buf, "t="))) {
671
+ char *q = p;
672
+ *(q--) = 0;
673
+
674
+ // Skip the `t=' and strip whitespace from
675
+ // the resulting strings
676
+ p += 2;
677
+ strip_white(p);
678
+ strip_white(buf);
679
+
680
+ // Grab the timevalue from the title string
681
+ if (timeval) *timeval = (float) atof(p);
682
+ }
683
+ else {
684
+ // No timevalue - just copy the string and strip
685
+ // any leading/trailing whitespace
686
+ if (timeval) *timeval = 0;
687
+ strip_white(buf);
688
+ }
689
+
690
+ // Copy the title string
691
+ if (title && titlelen) strncpy(title, buf, titlelen);
692
+
693
+ // Now ignore subsequent title lines and get the END string
694
+ while (strcasecmp(buf, "END"))
695
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
696
+
697
+ // Done!
698
+ return mdio_seterror(MDIO_SUCCESS);
699
+ }
700
+
701
+
702
+ // Used to determine the number of atoms in a g96 file, because
703
+ // VMD needs to know this for some reason.
704
+ static int g96_countatoms(md_file *mf) {
705
+ char buf[MAX_G96_LINE + 1];
706
+ int natoms;
707
+ int n;
708
+ long fpos;
709
+ float lastf;
710
+
711
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
712
+
713
+ fpos = ftell(mf->f);
714
+
715
+ natoms = 0;
716
+ for (;;) {
717
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1, 0) < 0)
718
+ break;
719
+ n = sscanf(buf, "%*6c%*6c%*6c%*6c %*f %*f %f", &lastf);
720
+ if (n == 1) natoms++;
721
+ else {
722
+ strip_white(buf);
723
+ if (!strcasecmp(buf, "END")) break;
724
+ }
725
+ }
726
+
727
+ fseek(mf->f, fpos, SEEK_SET);
728
+ return natoms;
729
+ }
730
+
731
+
732
+ // Reads an atom line from the G96 file
733
+ static int g96_rec(md_file *mf, md_atom *ma) {
734
+ char buf[MAX_G96_LINE + 1];
735
+ char atomnum[7];
736
+ int n;
737
+
738
+ // Check parameters
739
+ if (!mf || !ma) return mdio_seterror(MDIO_BADPARAMS);
740
+
741
+ // Read in a line, assuming it is an atom line
742
+ do {
743
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1, 0) < 0) return -1;
744
+ } while (buf[0] == '#' || strlen(buf) == 0);
745
+
746
+ n = sscanf(buf, "%6c%6c%6c%6c %f %f %f",
747
+ ma->resid, ma->resname, ma->atomname, atomnum,
748
+ &ma->pos[0], &ma->pos[1], &ma->pos[2]);
749
+ if (n == 7) {
750
+ atomnum[6] = 0;
751
+ ma->resid[6] = 0;
752
+ ma->resname[6] = 0;
753
+ ma->atomname[6] = 0;
754
+
755
+ strip_white(atomnum);
756
+ strip_white(ma->resid);
757
+ strip_white(ma->resname);
758
+ strip_white(ma->atomname);
759
+
760
+ ma->atomnum = atoi(atomnum);
761
+
762
+ ma->pos[0] *= ANGS_PER_NM;
763
+ ma->pos[1] *= ANGS_PER_NM;
764
+ ma->pos[2] *= ANGS_PER_NM;
765
+
766
+ return 0;
767
+ }
768
+
769
+ return mdio_seterror(MDIO_BADFORMAT);
770
+ }
771
+
772
+
773
+ // Reads a timestep from a G96 file and stores the data in
774
+ // the generic md_ts structure. Returns 0 on success or a
775
+ // negative number on error and sets mdio_errcode.
776
+ static int g96_timestep(md_file *mf, md_ts *ts) {
777
+ char buf[MAX_G96_LINE + 1];
778
+ char stripbuf[MAX_G96_LINE + 1];
779
+ float pos[3], x[3], y[3], z[3], *currAtom;
780
+ long fpos;
781
+ int n, i, boxItems;
782
+
783
+ // Check parameters
784
+ if (!mf || !ts) return mdio_seterror(MDIO_BADPARAMS);
785
+
786
+ // Allocate data space for the timestep, using the number of atoms
787
+ // determined by open_g96_read().
788
+ ts->pos = (float *) malloc(sizeof(float) * 3 * ts->natoms);
789
+ if (!ts->pos) {
790
+ return mdio_seterror(MDIO_BADMALLOC);
791
+ }
792
+ currAtom = ts->pos;
793
+
794
+ // The timesteps follow the header in a fixed block
795
+ // format:
796
+ //
797
+ // TIMESTEP
798
+ // <step number> <time value>
799
+ // END
800
+ // POSITIONRED
801
+ // <x float> <y float> <z float>
802
+ // . . .
803
+ // . . .
804
+ // . . .
805
+ // END
806
+ // VELOCITYRED
807
+ // <x float> <y float> <z float>
808
+ // . . .
809
+ // . . .
810
+ // . . .
811
+ // END
812
+ // BOX
813
+ // <x float> <y float> <z float>
814
+ // END
815
+ //
816
+ // -----
817
+ //
818
+ // The TIMESTEP, VELOCITY and BOX blocks are optional.
819
+ // Floats are written in 15.9 precision.
820
+ //
821
+ // Reference: GROMACS 2.0 user manual
822
+ // http://rugmd4.chem.rug.nl/~gmx/online2.0/g96.html
823
+
824
+ // First, look for an (optional) title block and skip it
825
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
826
+
827
+ if (!strcasecmp(buf, "TITLE")) {
828
+ // skip over the text until we reach 'END'
829
+ while (strcasecmp(buf, "END")) {
830
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
831
+ }
832
+
833
+ // Read in the next line
834
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
835
+ }
836
+
837
+ // Next, look for a timestep block
838
+ if (!strcasecmp(buf, "TIMESTEP")) {
839
+ // Read in the value line
840
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
841
+
842
+ // Extract the time value and the timestep index
843
+ n = sscanf(buf, "%d %f", &ts->step, &ts->time);
844
+ if (n != 2) return mdio_seterror(MDIO_BADFORMAT);
845
+
846
+ // Read the "END" line
847
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
848
+ if (strcasecmp(buf, "END"))
849
+ return mdio_seterror(MDIO_BADFORMAT);
850
+
851
+ // Read in the next line
852
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
853
+ }
854
+ else {
855
+ // No timestep specified -- set to zero
856
+ ts->step = 0;
857
+ ts->time = 0;
858
+ }
859
+
860
+ // At this point a POSITION or POSITIONRED block
861
+ // is REQUIRED by the format
862
+ if (!strcasecmp(buf, "POSITIONRED")) {
863
+
864
+ // So now we read in some atoms
865
+ i = 0;
866
+ while (i < ts->natoms) {
867
+ // Read in an atom
868
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0)
869
+ return -1;
870
+
871
+ // We shouldn't reach the end yet
872
+ if (!strcasecmp(buf, "END"))
873
+ return mdio_seterror(MDIO_BADFORMAT);
874
+
875
+ // Get the x,y,z coordinates
876
+ n = sscanf(buf, "%f %f %f", &pos[0], &pos[1], &pos[2]);
877
+
878
+ // Ignore improperly formatted lines
879
+ if (n == 3) {
880
+ pos[0] *= ANGS_PER_NM;
881
+ pos[1] *= ANGS_PER_NM;
882
+ pos[2] *= ANGS_PER_NM;
883
+
884
+ // Copy the atom data into the array
885
+ memcpy(currAtom, pos, sizeof(float) * 3);
886
+ currAtom += 3;
887
+ i++;
888
+ }
889
+ }
890
+ }
891
+ else if (!strcasecmp(buf, "POSITION") || !strcasecmp(buf, "REFPOSITION")) {
892
+ /*
893
+ char resnum[7];
894
+ char resname[7];
895
+ char atomname[7];
896
+ char atomnum[7];
897
+ */
898
+
899
+ // So now we read in some atoms
900
+ i = 0;
901
+ while (i < ts->natoms) {
902
+ // Read in the first line
903
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1, 0) < 0)
904
+ return -1;
905
+
906
+ // We shouldn't reach the end yet
907
+ strcpy(stripbuf, buf);
908
+ strip_white(stripbuf);
909
+ if (!strcasecmp(stripbuf, "END"))
910
+ return mdio_seterror(MDIO_BADFORMAT);
911
+
912
+ // Get the x,y,z coordinates and name data
913
+ n = sscanf(buf, "%*6c%*6c%*6c%*6c %f %f %f",
914
+ &pos[0], &pos[1], &pos[2]);
915
+
916
+ // Ignore improperly formatted lines
917
+ if (n == 3) {
918
+ pos[0] *= ANGS_PER_NM;
919
+ pos[1] *= ANGS_PER_NM;
920
+ pos[2] *= ANGS_PER_NM;
921
+
922
+ // Copy the atom data into the linked list item
923
+ memcpy(currAtom, pos, sizeof(float) * 3);
924
+ currAtom += 3;
925
+ i++;
926
+ }
927
+ }
928
+ }
929
+ else {
930
+ return mdio_seterror(MDIO_BADFORMAT);
931
+ }
932
+
933
+ // Read the END keyword
934
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0)
935
+ return -1;
936
+ if (strcasecmp(buf, "END"))
937
+ return mdio_seterror(MDIO_BADFORMAT);
938
+
939
+ // ... another problem: there may or may not be a VELOCITY
940
+ // block or a BOX block, so we need to read one line beyond
941
+ // the POSITION block to determine this. If neither VEL. nor
942
+ // BOX are present we've read a line too far and infringed
943
+ // on the next timestep, so we need to keep track of the
944
+ // position now for a possible fseek() later to backtrack.
945
+ fpos = ftell(mf->f);
946
+
947
+ // Now we must read in the velocities and the box, if present
948
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) {
949
+ // It's okay if we end the file here; any other errors need to be
950
+ // reported.
951
+ if (mdio_errcode == MDIO_EOF)
952
+ return mdio_seterror(MDIO_SUCCESS);
953
+ else
954
+ return -1;
955
+ }
956
+
957
+ // Is there a velocity block present ?
958
+ if (!strcasecmp(buf, "VELOCITY") || !strcasecmp(buf, "VELOCITYRED")) {
959
+ // Ignore all the coordinates - VMD doesn't use them
960
+ for (;;) {
961
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0)
962
+ return -1;
963
+ if (!strcasecmp(buf, "END")) break;
964
+ }
965
+
966
+ // Again, record our position because we may need
967
+ // to fseek here later if we read too far.
968
+ fpos = ftell(mf->f);
969
+
970
+ // Go ahead and read the next line.
971
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
972
+ }
973
+
974
+ // Is there a box present ?
975
+ if (!strcasecmp(buf, "BOX")) {
976
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) return -1;
977
+ boxItems = sscanf(buf, " %f %f %f %f %f %f %f %f %f",
978
+ &x[0], &y[1], &z[2], &x[1], &x[2], &y[0], &y[2], &z[0], &z[1]);
979
+ if (boxItems == 3) {
980
+ x[1] = x[2] = 0;
981
+ y[0] = y[2] = 0;
982
+ z[0] = z[1] = 0;
983
+ }
984
+ else if (boxItems != 9)
985
+ return mdio_seterror(MDIO_BADFORMAT);
986
+
987
+ // Allocate the box and convert the vectors.
988
+ ts->box = (md_box *) malloc(sizeof(md_box));
989
+ if (mdio_readbox(ts->box, x, y, z) < 0) {
990
+ free(ts->box);
991
+ ts->box = NULL;
992
+ return mdio_seterror(MDIO_BADFORMAT);
993
+ }
994
+
995
+ if (mdio_readline(mf, buf, MAX_G96_LINE + 1) < 0) {
996
+ free(ts->box);
997
+ ts->box = NULL;
998
+ return -1;
999
+ }
1000
+ if (strcasecmp(buf, "END")) {
1001
+ free(ts->box);
1002
+ ts->box = NULL;
1003
+ return mdio_seterror(MDIO_BADFORMAT);
1004
+ }
1005
+ }
1006
+ else {
1007
+ // We have read too far, so fseek back to the
1008
+ // last known safe position so we don't return
1009
+ // with the file pointer set infringing on the
1010
+ // next timestep data.
1011
+ fseek(mf->f, fpos, SEEK_SET);
1012
+ }
1013
+
1014
+ // We're done!
1015
+ return mdio_seterror(MDIO_SUCCESS);
1016
+ }
1017
+
1018
+
1019
+ // Attempts to read header data from a GROMACS structure file
1020
+ // The GROMACS header format is as follows (fixed, 2 lines ASCII):
1021
+ // <title> [ n= <timevalue> ]
1022
+ // <num atoms>
1023
+ static int gro_header(md_file *mf, char *title, int titlelen, float *timeval,
1024
+ int *natoms, int rewind) {
1025
+ char buf[MAX_GRO_LINE + 1];
1026
+ long fpos;
1027
+ char *p;
1028
+
1029
+ // Check parameters
1030
+ if (!mf)
1031
+ return mdio_seterror(MDIO_BADPARAMS);
1032
+
1033
+ // Get the current file position for rewinding later
1034
+ fpos = ftell(mf->f);
1035
+
1036
+ // The header consists of 2 lines - get the first line
1037
+ if (mdio_readline(mf, buf, MAX_GRO_LINE + 1) < 0) return -1;
1038
+
1039
+ // The timevalue can be included in the title string
1040
+ // after a "t=" prefix.
1041
+ if ((p = (char *) strstr(buf, "t="))) {
1042
+ char *q = p;
1043
+ *(q--) = 0;
1044
+
1045
+ // Skip the `t=' and strip whitespace from
1046
+ // the resulting strings
1047
+ p += 2;
1048
+ strip_white(p);
1049
+ strip_white(buf);
1050
+
1051
+ // Grab the timevalue from the title string
1052
+ if (timeval) *timeval = (float) atof(p);
1053
+ } else {
1054
+ // No timevalue - just copy the string
1055
+ if (timeval) *timeval = 0;
1056
+ }
1057
+
1058
+ // Copy the title string
1059
+ if (title && titlelen) strncpy(title, buf, titlelen);
1060
+
1061
+ // Get the second line and grab the number of atoms
1062
+ if (mdio_readline(mf, buf, MAX_GRO_LINE + 1) < 0) return -1;
1063
+
1064
+ // Store the number of atoms
1065
+ if (natoms && (!(*natoms = atoi(buf))))
1066
+ return mdio_seterror(MDIO_BADFORMAT);
1067
+
1068
+ // Now we rewind the file so that subsequent calls to
1069
+ // gro_timestep() will succeed. gro_timestep() requires
1070
+ // the header to be at the current file pointer.
1071
+ if (rewind)
1072
+ fseek(mf->f, fpos, SEEK_SET);
1073
+
1074
+ return 0; // Done!
1075
+ }
1076
+
1077
+
1078
+ // Reads one atom record from a GROMACS file. Returns GMX_SUCCESS
1079
+ // on success or a negative number on error.
1080
+ //
1081
+ // Record format (one line, fixed):
1082
+ // rrrrrRRRRRaaaaaAAAAA <x pos> <y pos> <z pos> <x vel> <y vel> <z vel>
1083
+ //
1084
+ // r = residue number
1085
+ // R = residue name
1086
+ // a = atom name
1087
+ // A = atom number
1088
+ //
1089
+ static int gro_rec(md_file *mf, md_atom *ma) {
1090
+ char buf[MAX_GRO_LINE + 1];
1091
+ char atomnum[6];
1092
+ char xposc[12], yposc[12], zposc[12];
1093
+ int n;
1094
+
1095
+ if (!mf)
1096
+ return mdio_seterror(MDIO_BADPARAMS);
1097
+
1098
+ do {
1099
+ if (mdio_readline(mf, buf, MAX_GRO_LINE + 1, 0) < 0)
1100
+ return -1;
1101
+ } while (buf[0] == '#' || !strlen(buf));
1102
+
1103
+ // Read in the fields
1104
+ n = sscanf(buf, "%5c%5c%5c%5c%8c%8c%8c",
1105
+ ma->resid, ma->resname, ma->atomname, atomnum,
1106
+ xposc, yposc, zposc);
1107
+
1108
+ if (n != 7)
1109
+ return mdio_seterror(MDIO_BADFORMAT);
1110
+
1111
+ // Null terminate the strings
1112
+ ma->resname[5] = 0;
1113
+ ma->atomname[5] = 0;
1114
+ ma->resid[5] = 0;
1115
+ atomnum[5] = 0;
1116
+ xposc[8] = 0;
1117
+ yposc[8] = 0;
1118
+ zposc[8] = 0;
1119
+
1120
+ if ((sscanf(xposc, "%f", &ma->pos[0]) != 1) ||
1121
+ (sscanf(yposc, "%f", &ma->pos[1]) != 1) ||
1122
+ (sscanf(zposc, "%f", &ma->pos[2]) != 1)) {
1123
+ return mdio_seterror(MDIO_BADFORMAT);
1124
+ }
1125
+
1126
+ // Convert strings to numbers
1127
+ strip_white(atomnum);
1128
+ ma->atomnum = atoi(atomnum);
1129
+
1130
+ // Convert nanometers to angstroms
1131
+ ma->pos[0] *= ANGS_PER_NM;
1132
+ ma->pos[1] *= ANGS_PER_NM;
1133
+ ma->pos[2] *= ANGS_PER_NM;
1134
+
1135
+ // Strip leading and trailing whitespace
1136
+ strip_white(ma->atomname);
1137
+ strip_white(ma->resname);
1138
+ strip_white(ma->resid);
1139
+
1140
+ return 0;
1141
+ }
1142
+
1143
+
1144
+ // Reads in a timestep from a .gro file. Ignores the data
1145
+ // not needed for a timestep, so is a little faster than
1146
+ // calling gro_rec() for each atom. Also reads in the
1147
+ // header block.
1148
+ //
1149
+ static int gro_timestep(md_file *mf, md_ts *ts) {
1150
+ char buf[MAX_GRO_LINE + 1];
1151
+ long coord;
1152
+ int i, n, boxItems;
1153
+ float x[3], y[3], z[3];
1154
+ char xposc[12], yposc[12], zposc[12];
1155
+
1156
+ if (!mf || !ts)
1157
+ return mdio_seterror(MDIO_BADPARAMS);
1158
+
1159
+ if (gro_header(mf, NULL, 0, &ts->time, &ts->natoms, 0) < 0)
1160
+ return -1;
1161
+
1162
+ ts->pos = (float *) malloc(3 * sizeof(float) * ts->natoms);
1163
+ if (!ts->pos)
1164
+ return mdio_seterror(MDIO_BADMALLOC);
1165
+
1166
+ coord = 0;
1167
+ for (i = 0; i < ts->natoms; i++) {
1168
+ if (mdio_readline(mf, buf, MAX_GRO_LINE + 1, 0) < 0) {
1169
+ free(ts->pos);
1170
+ return -1;
1171
+ }
1172
+
1173
+ n = sscanf(buf, "%*5c%*5c%*5c%*5c%8c%8c%8c", xposc, yposc, zposc);
1174
+ if (n != 3)
1175
+ return mdio_seterror(MDIO_BADFORMAT);
1176
+
1177
+ if ((sscanf(xposc, "%f", &ts->pos[coord ]) != 1) ||
1178
+ (sscanf(yposc, "%f", &ts->pos[coord + 1]) != 1) ||
1179
+ (sscanf(zposc, "%f", &ts->pos[coord + 2]) != 1)) {
1180
+ return mdio_seterror(MDIO_BADFORMAT);
1181
+ }
1182
+
1183
+ ts->pos[coord ] *= ANGS_PER_NM;
1184
+ ts->pos[coord + 1] *= ANGS_PER_NM;
1185
+ ts->pos[coord + 2] *= ANGS_PER_NM;
1186
+
1187
+ coord += 3;
1188
+ }
1189
+
1190
+ // Read the box, stored as three vectors representing its edges
1191
+ if (mdio_readline(mf, buf, MAX_GRO_LINE + 1, 0) < 0) {
1192
+ free(ts->pos);
1193
+ return -1;
1194
+ }
1195
+
1196
+ boxItems = sscanf(buf, " %f %f %f %f %f %f %f %f %f",
1197
+ &x[0], &y[1], &z[2], &x[1], &x[2], &y[0], &y[2], &z[0], &z[1]);
1198
+
1199
+ // File may only include three scalars for the box information -- if
1200
+ // that's the case, the box is orthoganal.
1201
+ if (boxItems == 3) {
1202
+ x[1] = x[2] = 0;
1203
+ y[0] = y[2] = 0;
1204
+ z[0] = z[1] = 0;
1205
+ } else if (boxItems != 9) {
1206
+ free(ts->pos);
1207
+ return -1;
1208
+ }
1209
+
1210
+ // Allocate the box and convert the vectors.
1211
+ ts->box = (md_box *) malloc(sizeof(md_box));
1212
+ if (mdio_readbox(ts->box, x, y, z) < 0) {
1213
+ free(ts->pos);
1214
+ free(ts->box);
1215
+ ts->box = NULL;
1216
+ return -1;
1217
+ }
1218
+
1219
+ return 0;
1220
+ }
1221
+
1222
+
1223
+ // Attempts to read header data from a .trX trajectory file
1224
+ //
1225
+ // The .trX header format is as follows:
1226
+ //
1227
+ // 4 bytes - magic number (0x07C9)
1228
+ // ...
1229
+ //
1230
+ static int trx_header(md_file *mf, int rewind) {
1231
+ int magic;
1232
+ trx_hdr *hdr;
1233
+ long fpos;
1234
+
1235
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
1236
+
1237
+ // In case we need to rewind
1238
+ fpos = ftell(mf->f);
1239
+
1240
+ // We need to store some data to the trX header data
1241
+ // structure inside the md_file structure
1242
+ hdr = mf->trx;
1243
+ if (!mf->trx) return mdio_seterror(MDIO_BADPARAMS);
1244
+
1245
+ // Read the magic number
1246
+ if (trx_int(mf, &magic) < 0) return -1;
1247
+ if (magic != TRX_MAGIC) {
1248
+ // Try reverse endianism
1249
+ swap4_aligned(&magic, 1);
1250
+ if (magic != TRX_MAGIC) return mdio_seterror(MDIO_BADFORMAT);
1251
+
1252
+ // Enable byte swapping (actually works, too!)
1253
+ mf->rev = 1;
1254
+ }
1255
+
1256
+ // Read the version number.
1257
+ // XXX. this is not the version number, but the storage size
1258
+ // of the following XDR encoded string.
1259
+ // the 'title' string is in fact the version identifier.
1260
+ // since VMD does not use any of that, it does no harm,
1261
+ // but is should still be fixed occasionally. AK 2005/01/08.
1262
+
1263
+ if(mf->fmt!=MDFMT_TRJ) {
1264
+ // It appears that TRJ files either don't contain a version
1265
+ // number or don't have a length-delimiter on the string,
1266
+ // whereas TRR files do contain both. Thus, with TRJ, we just
1267
+ // assume that the version number is the string length and
1268
+ // just hope for the best. -- WLD 2006/07/09
1269
+ if (trx_int(mf, &hdr->version) < 0) return -1;
1270
+ }
1271
+
1272
+ // Read in the title string
1273
+ if (trx_string(mf, hdr->title, MAX_TRX_TITLE) < 0)
1274
+ return -1;
1275
+
1276
+ // Read in some size data
1277
+ if (trx_int(mf, &hdr->ir_size) < 0) return -1;
1278
+ if (trx_int(mf, &hdr->e_size) < 0) return -1;
1279
+ if (trx_int(mf, &hdr->box_size) < 0) return -1;
1280
+ if (trx_int(mf, &hdr->vir_size) < 0) return -1;
1281
+ if (trx_int(mf, &hdr->pres_size) < 0) return -1;
1282
+ if (trx_int(mf, &hdr->top_size) < 0) return -1;
1283
+ if (trx_int(mf, &hdr->sym_size) < 0) return -1;
1284
+ if (trx_int(mf, &hdr->x_size) < 0) return -1;
1285
+ if (trx_int(mf, &hdr->v_size) < 0) return -1;
1286
+ if (trx_int(mf, &hdr->f_size) < 0) return -1;
1287
+ if (trx_int(mf, &hdr->natoms) < 0) return -1;
1288
+ if (trx_int(mf, &hdr->step) < 0) return -1;
1289
+ if (trx_int(mf, &hdr->nre) < 0) return -1;
1290
+
1291
+ // Make sure there are atoms...
1292
+ if (!hdr->natoms) return mdio_seterror(MDIO_BADFORMAT);
1293
+
1294
+ // Try to determine precision (float? double?)
1295
+ if (hdr->x_size) mf->prec = hdr->x_size / (hdr->natoms * 3);
1296
+ else if (hdr->v_size) mf->prec = hdr->v_size / (hdr->natoms * 3);
1297
+ else if (hdr->f_size) mf->prec = hdr->f_size / (hdr->natoms * 3);
1298
+ else return mdio_seterror(MDIO_BADPRECISION);
1299
+
1300
+ if (mf->prec != sizeof(float) && mf->prec != sizeof(double)) {
1301
+ // We have no data types this size! The
1302
+ // file must've been generated on another
1303
+ // platform
1304
+ return mdio_seterror(MDIO_BADPRECISION);
1305
+ }
1306
+
1307
+ // Read in timestep and lambda
1308
+ if (trx_real(mf, &hdr->t) < 0) return -1;
1309
+ if (trx_real(mf, &hdr->lambda) < 0) return -1;
1310
+
1311
+ // Rewind if necessary
1312
+ if (rewind) fseek(mf->f, fpos, SEEK_SET);
1313
+
1314
+ return 0;
1315
+ }
1316
+
1317
+
1318
+ // Reads in an integer and stores it in y. Returns GMX_SUCCESS
1319
+ // on success or a negative number on error.
1320
+ static int trx_int(md_file *mf, int *y) {
1321
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
1322
+
1323
+ // sanity check.
1324
+ if (sizeof(int) != 4) return mdio_seterror(MDIO_SIZEERROR);
1325
+
1326
+ if (y) {
1327
+ if (fread(y, 4, 1, mf->f) != 1)
1328
+ return mdio_seterror(MDIO_IOERROR);
1329
+ if (mf->rev) swap4_aligned(y, 1);
1330
+ }
1331
+ else if (fseek(mf->f, 4, SEEK_CUR) != 0)
1332
+ return mdio_seterror(MDIO_IOERROR);
1333
+
1334
+ return mdio_seterror(MDIO_SUCCESS);
1335
+ }
1336
+
1337
+
1338
+ // Reads in either a float or a double, depending on the
1339
+ // precision, and stores that number in y. Returns
1340
+ // GMX_SUCCESS on success or a negative number on error.
1341
+ static int trx_real(md_file *mf, float *y) {
1342
+ double x;
1343
+
1344
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
1345
+
1346
+ switch (mf->prec) {
1347
+ case sizeof(float):
1348
+ if (!y) {
1349
+ if (fseek(mf->f, mf->prec, SEEK_CUR) != 0)
1350
+ return mdio_seterror(MDIO_IOERROR);
1351
+ } else {
1352
+ if (fread(y, mf->prec, 1, mf->f) != 1)
1353
+ return mdio_seterror(MDIO_IOERROR);
1354
+ if (mf->rev) swap4_aligned(y, 1);
1355
+ }
1356
+ return mdio_seterror(MDIO_SUCCESS);
1357
+
1358
+ case sizeof(double):
1359
+ if (!y) {
1360
+ if (fseek(mf->f, mf->prec, SEEK_CUR) != 0)
1361
+ return mdio_seterror(MDIO_IOERROR);
1362
+ } else {
1363
+ if (fread(&x, mf->prec, 1, mf->f) != 1)
1364
+ return mdio_seterror(MDIO_IOERROR);
1365
+ if (mf->rev) swap8_aligned(&x, 1);
1366
+ *y = (float) x;
1367
+ }
1368
+ return mdio_seterror(MDIO_SUCCESS);
1369
+
1370
+ default:
1371
+ return mdio_seterror(MDIO_BADPRECISION);
1372
+ }
1373
+
1374
+ }
1375
+
1376
+
1377
+ // Reads in a real-valued vector (taking precision into account).
1378
+ // Stores the vector in vec, and returns GMX_SUCCESS on success
1379
+ // or a negative number on error.
1380
+ static int trx_rvector(md_file *mf, float *vec) {
1381
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
1382
+
1383
+ if (!vec) {
1384
+ if (trx_real(mf, NULL) < 0) return -1;
1385
+ if (trx_real(mf, NULL) < 0) return -1;
1386
+ if (trx_real(mf, NULL) < 0) return -1;
1387
+ return mdio_seterror(MDIO_SUCCESS);
1388
+ } else {
1389
+ if (trx_real(mf, &vec[0]) < 0) return -1;
1390
+ if (trx_real(mf, &vec[1]) < 0) return -1;
1391
+ if (trx_real(mf, &vec[2]) < 0) return -1;
1392
+ return mdio_seterror(MDIO_SUCCESS);
1393
+ }
1394
+ }
1395
+
1396
+
1397
+ // Reads in a string by first reading an integer containing the
1398
+ // string's length, then reading in the string itself and storing
1399
+ // it in str. If the length is greater than max, it is truncated
1400
+ // and the rest of the string is skipped in the file. Returns the
1401
+ // length of the string on success or a negative number on error.
1402
+ static int trx_string(md_file *mf, char *str, int max) {
1403
+ int size;
1404
+ size_t ssize;
1405
+
1406
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
1407
+
1408
+ if (trx_int(mf, &size) < 0) return -1;
1409
+ ssize = (size_t)size;
1410
+
1411
+ if (str && size <= max) {
1412
+ if (fread(str, 1, size, mf->f) != ssize)
1413
+ return mdio_seterror(MDIO_IOERROR);
1414
+ str[size] = 0;
1415
+ return size;
1416
+ } else if (str) {
1417
+ if (fread(str, 1, max, mf->f) != ssize)
1418
+ return mdio_seterror(MDIO_IOERROR);
1419
+ if (fseek(mf->f, size - max, SEEK_CUR) != 0)
1420
+ return mdio_seterror(MDIO_IOERROR);
1421
+ str[max] = 0;
1422
+ return max;
1423
+ } else {
1424
+ if (fseek(mf->f, size, SEEK_CUR) != 0)
1425
+ return mdio_seterror(MDIO_IOERROR);
1426
+ return 0;
1427
+ }
1428
+ }
1429
+
1430
+
1431
+ // Reads in a timestep frame from the .trX file and returns the
1432
+ // data in a timestep structure. Returns NULL on error.
1433
+ static int trx_timestep(md_file *mf, md_ts *ts) {
1434
+ int i;
1435
+ float x[3], y[3], z[3];
1436
+ trx_hdr *hdr;
1437
+
1438
+ if (!mf || !ts) return mdio_seterror(MDIO_BADPARAMS);
1439
+ if (mf->fmt != MDFMT_TRJ && mf->fmt != MDFMT_TRR)
1440
+ return mdio_seterror(MDIO_WRONGFORMAT);
1441
+
1442
+ // Read the header
1443
+ if (trx_header(mf) < 0) return -1;
1444
+
1445
+ // We need some data from the trX header
1446
+ hdr = mf->trx;
1447
+ if (!hdr) return mdio_seterror(MDIO_BADPARAMS);
1448
+
1449
+ if (hdr->box_size) { // XXX need to check value of box_size!!
1450
+ if (trx_rvector(mf, x) < 0) return -1;
1451
+ if (trx_rvector(mf, y) < 0) return -1;
1452
+ if (trx_rvector(mf, z) < 0) return -1;
1453
+
1454
+ // Allocate the box and convert the vectors.
1455
+ ts->box = (md_box *) malloc(sizeof(md_box));
1456
+ if (mdio_readbox(ts->box, x, y, z) < 0) {
1457
+ free(ts->box);
1458
+ ts->box = NULL;
1459
+ return -1;
1460
+ }
1461
+ }
1462
+
1463
+ if (hdr->vir_size) {
1464
+ if (trx_rvector(mf, NULL) < 0) return -1;
1465
+ if (trx_rvector(mf, NULL) < 0) return -1;
1466
+ if (trx_rvector(mf, NULL) < 0) return -1;
1467
+ }
1468
+
1469
+ if (hdr->pres_size) {
1470
+ if (trx_rvector(mf, NULL) < 0) return -1;
1471
+ if (trx_rvector(mf, NULL) < 0) return -1;
1472
+ if (trx_rvector(mf, NULL) < 0) return -1;
1473
+ }
1474
+
1475
+ if (hdr->x_size) {
1476
+ ts->pos = (float *) malloc(sizeof(float) * 3 * hdr->natoms);
1477
+ if (!ts->pos)
1478
+ return mdio_seterror(MDIO_BADMALLOC);
1479
+
1480
+ ts->natoms = hdr->natoms;
1481
+ for (i = 0; i < hdr->natoms; i++) {
1482
+ if (trx_rvector(mf, &ts->pos[i * 3]) < 0) {
1483
+ mdio_tsfree(ts, 1);
1484
+ return -1;
1485
+ }
1486
+
1487
+ ts->pos[i * 3 ] *= ANGS_PER_NM;
1488
+ ts->pos[i * 3 + 1] *= ANGS_PER_NM;
1489
+ ts->pos[i * 3 + 2] *= ANGS_PER_NM;
1490
+ }
1491
+ }
1492
+
1493
+ if (hdr->v_size) {
1494
+ for (i = 0; i < hdr->natoms; i++) {
1495
+ if (trx_rvector(mf, NULL) < 0) {
1496
+ mdio_tsfree(ts, 1);
1497
+ return -1;
1498
+ }
1499
+ }
1500
+ }
1501
+
1502
+ if (hdr->f_size) {
1503
+ for (i = 0; i < hdr->natoms; i++) {
1504
+ if (trx_rvector(mf, NULL) < 0) {
1505
+ mdio_tsfree(ts, 1);
1506
+ return -1;
1507
+ }
1508
+ }
1509
+ }
1510
+
1511
+ return mdio_seterror(MDIO_SUCCESS);
1512
+ }
1513
+
1514
+
1515
+ // writes an int in big endian. Returns GMX_SUCCESS
1516
+ // on success or a negative number on error.
1517
+ static int put_trx_int(md_file *mf, int y) {
1518
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
1519
+
1520
+ // sanity check.
1521
+ if (sizeof(int) != 4) return mdio_seterror(MDIO_SIZEERROR);
1522
+
1523
+ if (mf->rev) swap4_aligned(&y, 1);
1524
+ if (fwrite(&y, 4, 1, mf->f) != 1)
1525
+ return mdio_seterror(MDIO_IOERROR);
1526
+
1527
+ return mdio_seterror(MDIO_SUCCESS);
1528
+ }
1529
+
1530
+ // writes a real in big-endian. Returns GMX_SUCCESS
1531
+ // on success or a negative number on error.
1532
+ static int put_trx_real(md_file *mf, float y) {
1533
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
1534
+
1535
+ if (mf->rev) swap4_aligned(&y, 1);
1536
+ if (fwrite(&y, 4, 1, mf->f) != 1)
1537
+ return mdio_seterror(MDIO_IOERROR);
1538
+
1539
+ return mdio_seterror(MDIO_SUCCESS);
1540
+ }
1541
+
1542
+
1543
+ // writes an xdr encoded string. Returns GMX_SUCCESS
1544
+ // on success or a negative number on error.
1545
+ static int put_trx_string(md_file *mf, const char *s) {
1546
+ if (!mf || !s) return mdio_seterror(MDIO_BADPARAMS);
1547
+
1548
+ // write: size of object, string length, string data
1549
+ size_t len = strlen(s);
1550
+ if ( put_trx_int(mf, len+1)
1551
+ || put_trx_int(mf, len)
1552
+ || (fwrite(s, len, 1, mf->f) != 1))
1553
+ return mdio_seterror(MDIO_IOERROR);
1554
+
1555
+ return mdio_seterror(MDIO_SUCCESS);
1556
+ }
1557
+
1558
+
1559
+ // xtc_int() - reads an integer from an xtc file
1560
+ static int xtc_int(md_file *mf, int *i) {
1561
+ unsigned char c[4];
1562
+
1563
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
1564
+ // sanity check.
1565
+ if (sizeof(int) != 4) return mdio_seterror(MDIO_SIZEERROR);
1566
+
1567
+ if (fread(c, 1, 4, mf->f) != 4) {
1568
+ if (feof(mf->f)) return mdio_seterror(MDIO_EOF);
1569
+ else if (ferror(mf->f)) return mdio_seterror(MDIO_IOERROR);
1570
+ else return mdio_seterror(MDIO_UNKNOWNERROR);
1571
+ }
1572
+
1573
+ if (i) *i = c[3] + (c[2] << 8) + (c[1] << 16) + (c[0] << 24);
1574
+ return mdio_seterror(MDIO_SUCCESS);
1575
+ }
1576
+
1577
+
1578
+ // xtc_float() - reads a float from an xtc file
1579
+ static int xtc_float(md_file *mf, float *f) {
1580
+ unsigned char c[4];
1581
+ int i;
1582
+
1583
+ if (!mf) return mdio_seterror(MDIO_BADPARAMS);
1584
+
1585
+ if (fread(c, 1, 4, mf->f) != 4) {
1586
+ if (feof(mf->f)) return mdio_seterror(MDIO_EOF);
1587
+ else if (ferror(mf->f)) return mdio_seterror(MDIO_IOERROR);
1588
+ else return mdio_seterror(MDIO_UNKNOWNERROR);
1589
+ }
1590
+
1591
+ if (f) {
1592
+ // By reading the number in as an integer and then
1593
+ // copying it to a floating point number we can
1594
+ // ensure proper endianness
1595
+ i = c[3] + (c[2] << 8) + (c[1] << 16) + (c[0] << 24);
1596
+ memcpy(f, &i, 4);
1597
+ }
1598
+ return mdio_seterror(MDIO_SUCCESS);
1599
+ }
1600
+
1601
+
1602
+ // xtc_data() - reads a specific amount of data from an xtc
1603
+ // file using the xdr format.
1604
+ static int xtc_data(md_file *mf, char *buf, int len) {
1605
+ if (!mf || len < 1) return mdio_seterror(MDIO_BADPARAMS);
1606
+ size_t slen = (size_t)len;
1607
+ if (buf) {
1608
+ if (fread(buf, 1, slen, mf->f) != slen) {
1609
+ if (feof(mf->f)) return mdio_seterror(MDIO_EOF);
1610
+ if (ferror(mf->f)) return mdio_seterror(MDIO_IOERROR);
1611
+ else return mdio_seterror(MDIO_UNKNOWNERROR);
1612
+ }
1613
+ if (len % 4) {
1614
+ if (fseek(mf->f, 4 - (len % 4), SEEK_CUR)) {
1615
+ if (feof(mf->f)) return mdio_seterror(MDIO_EOF);
1616
+ if (ferror(mf->f)) return mdio_seterror(MDIO_IOERROR);
1617
+ else return mdio_seterror(MDIO_UNKNOWNERROR);
1618
+ }
1619
+ }
1620
+ }
1621
+ else {
1622
+ int newlen;
1623
+ newlen = len;
1624
+ if (len % 4) newlen += (4 - (len % 4));
1625
+ if (fseek(mf->f, newlen, SEEK_CUR)) {
1626
+ if (feof(mf->f)) return mdio_seterror(MDIO_EOF);
1627
+ if (ferror(mf->f)) return mdio_seterror(MDIO_IOERROR);
1628
+ else return mdio_seterror(MDIO_UNKNOWNERROR);
1629
+ }
1630
+ }
1631
+ return len;
1632
+ }
1633
+
1634
+
1635
+ // xtc_timestep() - reads a timestep from an .xtc file.
1636
+ static int xtc_timestep(md_file *mf, md_ts *ts) {
1637
+ int n;
1638
+ float f, x[3], y[3], z[3];
1639
+
1640
+ int size = 0; // explicitly initialized to zero.
1641
+ float precision;
1642
+
1643
+ if (!mf || !ts) return mdio_seterror(MDIO_BADPARAMS);
1644
+ if (!mf->f) return mdio_seterror(MDIO_BADPARAMS);
1645
+ if (mf->fmt != MDFMT_XTC) return mdio_seterror(MDIO_WRONGFORMAT);
1646
+
1647
+ // Check magic number
1648
+ if (xtc_int(mf, &n) < 0) return -1;
1649
+ if (n != XTC_MAGIC) return mdio_seterror(MDIO_BADFORMAT);
1650
+
1651
+ // Get number of atoms
1652
+ if (xtc_int(mf, &n) < 0) return -1;
1653
+ ts->natoms = n;
1654
+
1655
+ // Get the simulation step
1656
+ if (xtc_int(mf, &n) < 0) return -1;
1657
+ ts->step = n;
1658
+
1659
+ // Get the time value
1660
+ if (xtc_float(mf, &f) < 0) return -1;
1661
+ ts->time = f;
1662
+
1663
+ // Read the basis vectors of the box
1664
+ if ( (xtc_float(mf, &x[0]) < 0) ||
1665
+ (xtc_float(mf, &x[1]) < 0) ||
1666
+ (xtc_float(mf, &x[2]) < 0) ||
1667
+ (xtc_float(mf, &y[0]) < 0) ||
1668
+ (xtc_float(mf, &y[1]) < 0) ||
1669
+ (xtc_float(mf, &y[2]) < 0) ||
1670
+ (xtc_float(mf, &z[0]) < 0) ||
1671
+ (xtc_float(mf, &z[1]) < 0) ||
1672
+ (xtc_float(mf, &z[2]) < 0) )
1673
+ return -1;
1674
+ // Allocate the box and convert the vectors.
1675
+ ts->box = (md_box *) malloc(sizeof(md_box));
1676
+ if (mdio_readbox(ts->box, x, y, z) < 0) {
1677
+ free(ts->box);
1678
+ ts->box = NULL;
1679
+ return -1;
1680
+ }
1681
+
1682
+ ts->pos = (float *) malloc(sizeof(float) * 3 * ts->natoms);
1683
+ if (!ts->pos) return mdio_seterror(MDIO_BADMALLOC);
1684
+ n = xtc_3dfcoord(mf, ts->pos, &size, &precision);
1685
+ if (n < 0) return -1;
1686
+
1687
+ /* Now we're left with the job of scaling... */
1688
+ for (n = 0; n < ts->natoms * 3; n++)
1689
+ ts->pos[n] *= ANGS_PER_NM;
1690
+
1691
+ return mdio_seterror(MDIO_SUCCESS);
1692
+ }
1693
+
1694
+
1695
+ ///////////////////////////////////////////////////////////////////////
1696
+ // This algorithm is an implementation of the 3dfcoord algorithm
1697
+ // written by Frans van Hoesel (hoesel@chem.rug.nl) as part of the
1698
+ // Europort project in 1995.
1699
+ ///////////////////////////////////////////////////////////////////////
1700
+
1701
+ // integer table used in decompression
1702
+ static int xtc_magicints[] = {
1703
+ 0, 0, 0, 0, 0, 0, 0, 0, 0,8, 10, 12, 16, 20, 25, 32, 40, 50, 64,
1704
+ 80, 101, 128, 161, 203, 256, 322, 406, 512, 645, 812, 1024, 1290,
1705
+ 1625, 2048, 2580, 3250, 4096, 5060, 6501, 8192, 10321, 13003, 16384,
1706
+ 20642, 26007, 32768, 41285, 52015, 65536, 82570, 104031, 131072,
1707
+ 165140, 208063, 262144, 330280, 416127, 524287, 660561, 832255,
1708
+ 1048576, 1321122, 1664510, 2097152, 2642245, 3329021, 4194304,
1709
+ 5284491, 6658042, 8388607, 10568983, 13316085, 16777216 };
1710
+
1711
+ #define FIRSTIDX 9
1712
+ /* note that magicints[FIRSTIDX-1] == 0 */
1713
+ #define LASTIDX (sizeof(xtc_magicints) / sizeof(*xtc_magicints))
1714
+
1715
+
1716
+ // returns the number of bits in the binary expansion of
1717
+ // the given integer.
1718
+ static int xtc_sizeofint(int size) {
1719
+ unsigned int num = 1;
1720
+ unsigned int ssize = (unsigned int)size;
1721
+ int nbits = 0;
1722
+
1723
+ while (ssize >= num && nbits < 32) {
1724
+ nbits++;
1725
+ num <<= 1;
1726
+ }
1727
+ return nbits;
1728
+ }
1729
+
1730
+ // calculates the number of bits a set of integers, when compressed,
1731
+ // will take up.
1732
+ static int xtc_sizeofints(int nints, unsigned int *sizes) {
1733
+ int i;
1734
+ unsigned int num;
1735
+ unsigned int nbytes, nbits, bytes[32], bytecnt, tmp;
1736
+ nbytes = 1;
1737
+ bytes[0] = 1;
1738
+ nbits = 0;
1739
+ for (i=0; i < nints; i++) {
1740
+ tmp = 0;
1741
+ for (bytecnt = 0; bytecnt < nbytes; bytecnt++) {
1742
+ tmp = bytes[bytecnt] * sizes[i] + tmp;
1743
+ bytes[bytecnt] = tmp & 0xff;
1744
+ tmp >>= 8;
1745
+ }
1746
+ while (tmp != 0) {
1747
+ bytes[bytecnt++] = tmp & 0xff;
1748
+ tmp >>= 8;
1749
+ }
1750
+ nbytes = bytecnt;
1751
+ }
1752
+ num = 1;
1753
+ nbytes--;
1754
+ while (bytes[nbytes] >= num) {
1755
+ nbits++;
1756
+ num *= 2;
1757
+ }
1758
+ return nbits + nbytes * 8;
1759
+ }
1760
+
1761
+ // reads bits from a buffer.
1762
+ static int xtc_receivebits(int *buf, int nbits) {
1763
+ int cnt, num;
1764
+ unsigned int lastbits, lastbyte;
1765
+ unsigned char * cbuf;
1766
+ int mask = (1 << nbits) -1;
1767
+
1768
+ cbuf = ((unsigned char *)buf) + 3 * sizeof(*buf);
1769
+ cnt = buf[0];
1770
+ lastbits = (unsigned int) buf[1];
1771
+ lastbyte = (unsigned int) buf[2];
1772
+
1773
+ num = 0;
1774
+ while (nbits >= 8) {
1775
+ lastbyte = ( lastbyte << 8 ) | cbuf[cnt++];
1776
+ num |= (lastbyte >> lastbits) << (nbits - 8);
1777
+ nbits -=8;
1778
+ }
1779
+ if (nbits > 0) {
1780
+ if (lastbits < (unsigned int)nbits) {
1781
+ lastbits += 8;
1782
+ lastbyte = (lastbyte << 8) | cbuf[cnt++];
1783
+ }
1784
+ lastbits -= nbits;
1785
+ num |= (lastbyte >> lastbits) & ((1 << nbits) -1);
1786
+ }
1787
+ num &= mask;
1788
+ buf[0] = cnt;
1789
+ buf[1] = lastbits;
1790
+ buf[2] = lastbyte;
1791
+ return num;
1792
+ }
1793
+
1794
+ // decompresses small integers from the buffer
1795
+ // sizes parameter has to be non-zero to prevent divide-by-zero
1796
+ static void xtc_receiveints(int *buf, const int nints, int nbits,
1797
+ unsigned int *sizes, int *nums) {
1798
+ int bytes[32];
1799
+ int i, j, nbytes, p, num;
1800
+
1801
+ bytes[1] = bytes[2] = bytes[3] = 0;
1802
+ nbytes = 0;
1803
+ while (nbits > 8) {
1804
+ bytes[nbytes++] = xtc_receivebits(buf, 8);
1805
+ nbits -= 8;
1806
+ }
1807
+ if (nbits > 0) {
1808
+ bytes[nbytes++] = xtc_receivebits(buf, nbits);
1809
+ }
1810
+ for (i = nints-1; i > 0; i--) {
1811
+ num = 0;
1812
+ for (j = nbytes-1; j >=0; j--) {
1813
+ num = (num << 8) | bytes[j];
1814
+ p = num / sizes[i];
1815
+ bytes[j] = p;
1816
+ num = num - p * sizes[i];
1817
+ }
1818
+ nums[i] = num;
1819
+ }
1820
+ nums[0] = bytes[0] | (bytes[1] << 8) | (bytes[2] << 16) | (bytes[3] << 24);
1821
+ }
1822
+
1823
+ // function that actually reads and writes compressed coordinates
1824
+ static int xtc_3dfcoord(md_file *mf, float *fp, int *size, float *precision) {
1825
+ static int *ip = NULL;
1826
+ static int oldsize;
1827
+ static int *buf;
1828
+
1829
+ int minint[3], maxint[3], *lip;
1830
+ int smallidx;
1831
+ unsigned sizeint[3], sizesmall[3], bitsizeint[3], size3;
1832
+ int flag, k;
1833
+ int small, smaller, i, is_smaller, run;
1834
+ float *lfp;
1835
+ int tmp, *thiscoord, prevcoord[3];
1836
+
1837
+ int bufsize, lsize;
1838
+ unsigned int bitsize;
1839
+ float inv_precision;
1840
+
1841
+ /* avoid uninitialized data compiler warnings */
1842
+ bitsizeint[0] = 0;
1843
+ bitsizeint[1] = 0;
1844
+ bitsizeint[2] = 0;
1845
+
1846
+ if (xtc_int(mf, &lsize) < 0) return -1;
1847
+
1848
+ if (*size != 0 && lsize != *size) return mdio_seterror(MDIO_BADFORMAT);
1849
+
1850
+ *size = lsize;
1851
+ size3 = *size * 3;
1852
+ if (*size <= 9) {
1853
+ for (i = 0; i < *size; i++) {
1854
+ if (xtc_float(mf, fp + (3 * i)) < 0) return -1;
1855
+ if (xtc_float(mf, fp + (3 * i) + 1) < 0) return -1;
1856
+ if (xtc_float(mf, fp + (3 * i) + 2) < 0) return -1;
1857
+ }
1858
+ return *size;
1859
+ }
1860
+ xtc_float(mf, precision);
1861
+ if (ip == NULL) {
1862
+ ip = (int *)malloc(size3 * sizeof(*ip));
1863
+ if (ip == NULL) return mdio_seterror(MDIO_BADMALLOC);
1864
+ bufsize = (int) (size3 * 1.2);
1865
+ buf = (int *)malloc(bufsize * sizeof(*buf));
1866
+ if (buf == NULL) return mdio_seterror(MDIO_BADMALLOC);
1867
+ oldsize = *size;
1868
+ } else if (*size > oldsize) {
1869
+ ip = (int *)realloc(ip, size3 * sizeof(*ip));
1870
+ if (ip == NULL) return mdio_seterror(MDIO_BADMALLOC);
1871
+ bufsize = (int) (size3 * 1.2);
1872
+ buf = (int *)realloc(buf, bufsize * sizeof(*buf));
1873
+ if (buf == NULL) return mdio_seterror(MDIO_BADMALLOC);
1874
+ oldsize = *size;
1875
+ }
1876
+ buf[0] = buf[1] = buf[2] = 0;
1877
+
1878
+ xtc_int(mf, &(minint[0]));
1879
+ xtc_int(mf, &(minint[1]));
1880
+ xtc_int(mf, &(minint[2]));
1881
+
1882
+ xtc_int(mf, &(maxint[0]));
1883
+ xtc_int(mf, &(maxint[1]));
1884
+ xtc_int(mf, &(maxint[2]));
1885
+
1886
+ sizeint[0] = maxint[0] - minint[0]+1;
1887
+ sizeint[1] = maxint[1] - minint[1]+1;
1888
+ sizeint[2] = maxint[2] - minint[2]+1;
1889
+
1890
+ /* check if one of the sizes is to big to be multiplied */
1891
+ if ((sizeint[0] | sizeint[1] | sizeint[2] ) > 0xffffff) {
1892
+ bitsizeint[0] = xtc_sizeofint(sizeint[0]);
1893
+ bitsizeint[1] = xtc_sizeofint(sizeint[1]);
1894
+ bitsizeint[2] = xtc_sizeofint(sizeint[2]);
1895
+ bitsize = 0; /* flag the use of large sizes */
1896
+ } else {
1897
+ bitsize = xtc_sizeofints(3, sizeint);
1898
+ }
1899
+
1900
+ xtc_int(mf, &smallidx);
1901
+ smaller = xtc_magicints[FIRSTIDX > smallidx - 1 ? FIRSTIDX : smallidx - 1] / 2;
1902
+ small = xtc_magicints[smallidx] / 2;
1903
+ sizesmall[0] = sizesmall[1] = sizesmall[2] = xtc_magicints[smallidx];
1904
+
1905
+ /* check for zero values that would yield corrupted data */
1906
+ if ( !sizesmall[0] || !sizesmall[1] || !sizesmall[2] ) {
1907
+ printf("XTC corrupted, sizesmall==0 (case 1)\n");
1908
+ return -1;
1909
+ }
1910
+
1911
+
1912
+ /* buf[0] holds the length in bytes */
1913
+ if (xtc_int(mf, &(buf[0])) < 0) return -1;
1914
+
1915
+ if (xtc_data(mf, (char *) &buf[3], (int) buf[0]) < 0) return -1;
1916
+
1917
+ buf[0] = buf[1] = buf[2] = 0;
1918
+
1919
+ lfp = fp;
1920
+ inv_precision = 1.0f / (*precision);
1921
+ run = 0;
1922
+ i = 0;
1923
+ lip = ip;
1924
+ while (i < lsize) {
1925
+ thiscoord = (int *)(lip) + i * 3;
1926
+
1927
+ if (bitsize == 0) {
1928
+ thiscoord[0] = xtc_receivebits(buf, bitsizeint[0]);
1929
+ thiscoord[1] = xtc_receivebits(buf, bitsizeint[1]);
1930
+ thiscoord[2] = xtc_receivebits(buf, bitsizeint[2]);
1931
+ } else {
1932
+ xtc_receiveints(buf, 3, bitsize, sizeint, thiscoord);
1933
+ }
1934
+
1935
+ i++;
1936
+ thiscoord[0] += minint[0];
1937
+ thiscoord[1] += minint[1];
1938
+ thiscoord[2] += minint[2];
1939
+
1940
+ prevcoord[0] = thiscoord[0];
1941
+ prevcoord[1] = thiscoord[1];
1942
+ prevcoord[2] = thiscoord[2];
1943
+
1944
+
1945
+ flag = xtc_receivebits(buf, 1);
1946
+ is_smaller = 0;
1947
+ if (flag == 1) {
1948
+ run = xtc_receivebits(buf, 5);
1949
+ is_smaller = run % 3;
1950
+ run -= is_smaller;
1951
+ is_smaller--;
1952
+ }
1953
+ if (run > 0) {
1954
+ thiscoord += 3;
1955
+ for (k = 0; k < run; k+=3) {
1956
+ xtc_receiveints(buf, 3, smallidx, sizesmall, thiscoord);
1957
+ i++;
1958
+ thiscoord[0] += prevcoord[0] - small;
1959
+ thiscoord[1] += prevcoord[1] - small;
1960
+ thiscoord[2] += prevcoord[2] - small;
1961
+ if (k == 0) {
1962
+ /* interchange first with second atom for better
1963
+ * compression of water molecules
1964
+ */
1965
+ tmp = thiscoord[0]; thiscoord[0] = prevcoord[0];
1966
+ prevcoord[0] = tmp;
1967
+ tmp = thiscoord[1]; thiscoord[1] = prevcoord[1];
1968
+ prevcoord[1] = tmp;
1969
+ tmp = thiscoord[2]; thiscoord[2] = prevcoord[2];
1970
+ prevcoord[2] = tmp;
1971
+ *lfp++ = prevcoord[0] * inv_precision;
1972
+ *lfp++ = prevcoord[1] * inv_precision;
1973
+ *lfp++ = prevcoord[2] * inv_precision;
1974
+
1975
+ if ( !sizesmall[0] || !sizesmall[1] || !sizesmall[2] ) {
1976
+ printf("XTC corrupted, sizesmall==0 (case 2)\n");
1977
+ return -1;
1978
+ }
1979
+
1980
+ } else {
1981
+ prevcoord[0] = thiscoord[0];
1982
+ prevcoord[1] = thiscoord[1];
1983
+ prevcoord[2] = thiscoord[2];
1984
+ }
1985
+ *lfp++ = thiscoord[0] * inv_precision;
1986
+ *lfp++ = thiscoord[1] * inv_precision;
1987
+ *lfp++ = thiscoord[2] * inv_precision;
1988
+ }
1989
+ } else {
1990
+ *lfp++ = thiscoord[0] * inv_precision;
1991
+ *lfp++ = thiscoord[1] * inv_precision;
1992
+ *lfp++ = thiscoord[2] * inv_precision;
1993
+ }
1994
+ smallidx += is_smaller;
1995
+ if (is_smaller < 0) {
1996
+ small = smaller;
1997
+ if (smallidx > FIRSTIDX) {
1998
+ smaller = xtc_magicints[smallidx - 1] /2;
1999
+ } else {
2000
+ smaller = 0;
2001
+ }
2002
+ } else if (is_smaller > 0) {
2003
+ smaller = small;
2004
+ small = xtc_magicints[smallidx] / 2;
2005
+ }
2006
+ sizesmall[0] = sizesmall[1] = sizesmall[2] = xtc_magicints[smallidx] ;
2007
+ }
2008
+ return 1;
2009
+ }
2010
+ }
2011
+ }
2012
+ #endif
2013
+ #endif