moleculekit.binpos module#
- class moleculekit.binpos.BINPOSTrajectoryFile(filename, mode='r', force_overwrite=True, **kwargs)#
Bases:
objectInterface for reading and writing to an AMBER BINPOS file. This is a file-like object, that both reading or writing depending on the mode flag. It implements the context manager protocol, so you can also use it with the python ‘with’ statement.
The conventional units in the BINPOS file are angstroms. The format only supports storing the cartesian coordinates.
- Parameters:
filename (str) – The filename to open. A path to a file on disk.
mode ({'r', 'w'}) – The mode in which to open the file, either ‘r’ for read or ‘w’ for write.
force_overwrite (bool) – If opened in write mode, and a file by the name of filename already exists on disk, should we overwrite it?
min_chunk_size (int, default=100) – BINPOS, In read mode, we need to allocate a buffer in which to store the data without knowing how many frames are in the file. This parameter is the minimum size of the buffer to allocate.
chunk_size_multiplier (int, default=1.5) – In read mode, we need to allocate a buffer in which to store the data without knowing how many frames are in the file. We can guess this information based on the size of the file on disk, but it’s not perfect. This parameter inflates the guess by a multiplicative factor.
Examples
>>> # copy data from one file to another >>> with BINPOSTrajectoryFile('traj.binpos') as f: >>> xyz = f.read() >>> with BINPOSTrajectoryFile('out.binpos') as f: >>> f.write(xyz)
- __enter__()#
Support the context manager protocol
- __exit__(*exc_info)#
Support the context manager protocol
- close()#
Close the BINPOS file
- distance_unit#
- read(n_frames=None, stride=None, atom_indices=None)#
Read data from a BINPOS file
- Parameters:
n_frames (int, None) – The number of frames you would like to read from the file. If None, all of the remaining frames will be loaded.
stride (np.ndarray, optional) – Read only every stride-th frame.
atom_indices (array_like, optional) – If not none, then read only a subset of the atoms coordinates from the file. This may be slightly slower than the standard read because it required an extra copy, but will save memory.
- Returns:
xyz – The cartesian coordinates, in angstroms
- Return type:
np.ndarray, shape=(n_frames, n_atoms, 3), dtype=np.float32
- seek(offset, whence=0)#
Move to a new file position
- Parameters:
offset (int) – A number of frames.
whence ({0, 1, 2}) – 0: offset from start of file, offset should be >=0. 1: move relative to the current position, positive or negative 2: move relative to the end of file, offset should be <= 0. Seeking beyond the end of a file is not supported
- write(xyz)#
Write cartesian coordinates to a binpos file
- Parameters:
xyz (np.ndarray, dtype=np.float32, shape=(n_frames, n_atoms, 3)) – The cartesian coordinates of the atoms in every frame, in angstroms.
- moleculekit.binpos.load_binpos(filename, top=None, stride=None, atom_indices=None, frame=None)#
Load an AMBER .binpos file from disk.
The .binpos format is a cross-platform binary trajectory format produced by AMBER software. It stores only the atomic coordinates, and does not store any unit cell informations. Its use is discouraged.
- Parameters:
filename (path-like) – Path of AMBER binpos file.
stride (int, default=None) – Only read every stride-th frame
atom_indices (array_like, optional) – If not none, then read only a subset of the atoms coordinates from the file. This may be slightly slower than the standard read because it requires an extra copy, but will save memory.
frame (int, optional) – Use this option to load only a single frame from a trajectory on disk. If frame is None, the default, the entire trajectory will be loaded. If supplied,
stridewill be ignored.