2424 xyz = data["pos"]
2525"""
2626
27-
2827from __future__ import absolute_import , division , print_function , unicode_literals
2928
3029import glob
31- import io
3230import os
31+ import warnings
3332
3433import numpy as np
3534
3938
4039
4140def load (filename ):
42- """Universal load function for any type of data file It always returns just XYZ
43- positions - use fetch_block or hdf5_format.load_URI for loading the whole metadata
44-
45- Accepted file types
46- -------------------
47-
48- New-style URIs (HDF5 based storage)
49-
50- Joblib and text files were deprecated.
41+ """
42+ A function to load a single conformation from a URI. Deprecated.
43+ Use load_URI from hdf5_format instead.
5144
5245 Parameters
5346 ----------
@@ -56,23 +49,18 @@ def load(filename):
5649 filename to load or a URI
5750
5851 """
52+ warnings .warn ("polymerutils.load is deprecated. Use hdf5_format.load_URI instead." , DeprecationWarning )
53+
5954 if "::" in filename :
6055 return hdf5_format .load_URI (filename )["pos" ]
61-
62- raise ValueError ("Only URIs are supported in this version of polychrom" )
63-
6456
57+ raise ValueError ("Only URIs are supported in this version of polychrom" )
6558
6659
6760def fetch_block (folder , ind , full_output = False ):
6861 """
69- A more generic function to fetch block number "ind" from a trajectory in a folder
70-
71-
72- This function is useful both if you want to load both "old style" trajectories (block1.dat),
73- and "new style" trajectories ("blocks_1-50.h5")
74-
75- It will be used in files "show"
62+ A function to fetch a single block from a folder with a new-style trajectory.
63+ Old-style trajectores are deprecated.
7664
7765 Parameters
7866 ----------
@@ -92,12 +80,14 @@ def fetch_block(folder, ind, full_output=False):
9280
9381 if full_output==True, then dict with data and metadata; XYZ is under key "pos"
9482 """
83+ warnings .warn (
84+ "fetch_block is deprecated. Use hdf5_format.list_uris followed by hdf5_format.load_URI instead." ,
85+ DeprecationWarning ,
86+ )
87+
9588 blocksh5 = glob .glob (os .path .join (folder , "blocks*.h5" ))
96- blocksdat = glob .glob (os .path .join (folder , "block*.dat" ))
9789 ind = int (ind )
98- if (len (blocksh5 ) > 0 ) and (len (blocksdat ) > 0 ):
99- raise ValueError ("both .h5 and .dat files found in folder - exiting" )
100- if (len (blocksh5 ) == 0 ) and (len (blocksdat ) == 0 ):
90+ if len (blocksh5 ) == 0 :
10191 raise ValueError ("no blocks found" )
10292
10393 if len (blocksh5 ) > 0 :
@@ -113,21 +103,17 @@ def fetch_block(folder, ind, full_output=False):
113103 block = load_URI (blocksh5 [pos ] + f"::{ ind } " )
114104 if not full_output :
115105 return block ["pos" ]
106+ return block
116107
117- if len (blocksdat ) > 0 :
118- return load (os .path .join (folder , f"block{ ind } .dat" ))
119108 raise ValueError (f"Cannot find the block { ind } in the folder { folder } " )
120109
121110
122111def save (data , filename , mode = "txt" , pdbGroups = None ):
123112 """
124- Basically unchanged polymerutils.save function from openmm-polymer
125-
126-
127-
128- It is also very useful for saving files to PDB format to make them compatible
129- with nglview, pymol_show and others
113+ A legacy function, currently only kept for compatibility with PDB saving that is rarely used.
130114 """
115+ warnings .warn ("polymerutils.save is deprecated. Will be moved to legacy" , DeprecationWarning )
116+
131117 data = np .asarray (data , dtype = np .float32 )
132118
133119 if mode == "pdb" :
@@ -175,13 +161,10 @@ def add(st, n):
175161 filename .write ("C {0} {1} {2}" .format (* i ))
176162
177163 else :
178- raise ValueError ("Unknown mode : %s, use or pdb" % mode )
164+ raise ValueError (f "Unknown mode { mode } . Only 'pdb' and 'pyxyz' are supported." )
179165
180166
181167def rotation_matrix (rotate ):
182- """Calculates rotation matrix based on three rotation angles"""
183- tx , ty , tz = rotate
184- Rx = np .array ([[1 , 0 , 0 ], [0 , np .cos (tx ), - np .sin (tx )], [0 , np .sin (tx ), np .cos (tx )]])
185- Ry = np .array ([[np .cos (ty ), 0 , - np .sin (ty )], [0 , 1 , 0 ], [np .sin (ty ), 0 , np .cos (ty )]])
186- Rz = np .array ([[np .cos (tz ), - np .sin (tz ), 0 ], [np .sin (tz ), np .cos (tz ), 0 ], [0 , 0 , 1 ]])
187- return np .dot (Rx , np .dot (Ry , Rz ))
168+ warnings .warn ("rotation_matrix will be moved to polymer_analyses" , DeprecationWarning )
169+ from polychrom .polymer_analyses import rotation_matrix as rm
170+ return rm (rotate )
0 commit comments