CDTK.Tools.Utils module
Some miscellaneous tools
- CDTK.Tools.Utils.ReverseArray(array)[source]
Reverse array.
Parameters:
- array1D array_like
array to be reversed
- rtype:
Reversed array
- CDTK.Tools.Utils.ShiftArray(array, shift, **option)[source]
Shift array.
Parameters:
- array1D array_like
array to be shifted
- shiftint
amount of shifting, positive integer will shift the array to the right, negative integer will shift the array to the left.
- periodicBool, optional, default: True
if True, use the periodic boudary condition on the array edge (the right most array element which is right shifted will appear on the left most, and vice versa). If False, the new array element which enter the array as the right most or the left most elements will be set 0.0.
Returns:
Shifted array
- CDTK.Tools.Utils.atomicCoordinatesFromRlog(Rlog)[source]
Sort the entries of an Rlog file on a per atom basis
- Rlog:
t0 X01 Y01 Z01 X02 Y02 Z02 …… X0N Y0N Z0N t1 X11 Y11 Z11 X12 Y12 Z12 …… X1N Y1N Z1N … tf Xf1 Yf1 Zf1 Xf2 Yf2 Zf2 …… XfN YfN ZfN
- Returns as array
- [ [ [X01 Y01 Z01 ], [X02 Y02 Z02], …. [X0N Y0N Z0N] ],
[ [Xf1 Yf1 Zf1 ], [Xf2 Yf2 Zf2], …. [XfN YfN ZfN] ]
]
- CDTK.Tools.Utils.fileLineParser(path, regexp, functions=[])[source]
Parse a file line by line using a regexp to find matching values
path – path to the file being parsed regexp – a valid regexp with one or more parenthesis to catch matching
values
- functions – list of transformation functions to be applied to the matching
strings, e.g. “float” if provided should have as many elements as the number of elements to be matched from every matching line
- output:
List of lists, one list per matching line. Empty list if no matches.
- CDTK.Tools.Utils.getDenTable(finput, dof, **args)[source]
Return the next grid reduced density in table form
- Input:
finput - file object with the gden file dof - degree of freedom to look for
- Returns:
found - True/False, whether still data to be returned table - list of lists with x,y,z data
- CDTK.Tools.Utils.getDirectoryList(folder='./', file_name=None)[source]
Get trj_ subfolders in a given folder. If a file name is given, only trj_ subfolders are returned that contain a file with that name. The returned list is sorted.
- CDTK.Tools.Utils.getNextTime(finput)[source]
Return next time in data file
- Input:
finput - file object with the gpop file
- Returns:
time - time (float) or None if EOF is reached
- CDTK.Tools.Utils.getPopTable(finput, dof)[source]
Return the next grid population in table form
- Input:
finput - file object with the gpop file dof - degree of freedom to look for
- Returns:
found - True/False, whether still data to be returned table - list of lists with x,y data
- CDTK.Tools.Utils.loadDataStruct(fname)[source]
Load a data structure from a file
The data structure must have been saved as a string, for example by saveDataStruct
fname – path to the file with the data structure
- CDTK.Tools.Utils.readAuto(fname, **opts)[source]
Read an autocorrelation file into a complex array fname – path to file to be read or file object Options:
skip – integer, dafault 0. New row read every <skip> rows.
- CDTK.Tools.Utils.readFile(path)[source]
return a string with the contents of a file
path - path to the file to be read
- CDTK.Tools.Utils.readRlogRestricted(rlog, col0=0, coln=1)[source]
Read log file and return array with vals starting at col0, ending at col0 + coln
- CDTK.Tools.Utils.readTableFile(fname, **opts)[source]
read a file with data organized in table form and return a l[i,j] list
fname – path to file to be read or file object Options:
- mode – text string: “rows” (default) or “cols”
in “rows” mode the first index runs over the rows of the table
in “cols” mode the first index runs over the columns of the table
skip – integer, dafault 0. New row read every <skip> rows.
- CDTK.Tools.Utils.readTag(tag, string)[source]
In a string look for XML tag “tag” and return its content
tag - string containing the tag whose contents are to be retrieved string - text string
returns the contents between <tag> and </tag> or None if <tag> is not present.
- CDTK.Tools.Utils.readTagFromFile(tag, path)[source]
return a string with the contents between <tag> and </tag>
- CDTK.Tools.Utils.saveDataStruct(fname, obj)[source]
Store the string representation of a data structure to a file
The repr() function is used, this function is intended only for rather simple data structures made for example of nested lists and dictionaries.
obj – object to store fname – path to the file where to store the string
- CDTK.Tools.Utils.traj2vtf(atomlist, Rlog, vtfname='traj', mmlist=None, disp_n_atoms=None)[source]
Generate a trajectory in .vtf format
Useful for plots with VMD
Point charges represented by “X”
Input arguments:
atomlist – path to atomlist file Rlog – path to R.log file vtfname – vtf filename mmlist – path to MM region atomlist file disp_n_atoms – int; number of atoms to output (truncation for large systems)
- CDTK.Tools.Utils.traj2xyz(atomlist, geoms, filename='traj.xyz', comment='CDTK-generated traj file', timesteps=None)[source]
Generate a trajectory in .xyz format Useful for plots with VMD
- Parameters:
atomlist (list of strings) – list of atom symbols
geoms (numpy array [step, atoms, 3 ]) – geometries
filename (str, optional) – output filename. Defaults to ‘traj.xyz’.
comment (str, optional) – comment line. Defaults to ‘CDTK-generated traj file’.
timesteps (array of floats, optional) – time step information. Defaults to None.