Module that contains dcdreader class.
More...
|
subroutine | dcdfile_open (this, filename) |
| Opens file to read from. More...
|
|
subroutine | dcdfile_read_header (this, nframes, istart, nevery, iend, timestep, natoms) |
| Reads header of open DCD file. More...
|
|
subroutine | dcdfile_close (this) |
| Closes DCD file. More...
|
|
subroutine | dcdfile_read_next (this, xyz, box) |
| Reads next frame into memory. More...
|
|
subroutine | dcdfile_skip_next (this, n) |
| Skips reading this frame into memory. More...
|
|
Module that contains dcdreader class.
◆ dcdfile_close()
subroutine dcdfort_reader::dcdfile_close |
( |
class(dcdfile), intent(inout) |
this | ) |
|
Closes DCD file.
- Parameters
-
[in,out] | this | dcdreader object |
187 class(dcdfile),
intent(inout) :: this
◆ dcdfile_open()
subroutine dcdfort_reader::dcdfile_open |
( |
class(dcdfile), intent(inout) |
this, |
|
|
character (len=*), intent(in) |
filename |
|
) |
| |
Opens file to read from.
Also detects if the DCD file is compatible with this library and swaps endinness if necessary.
- Parameters
-
[in,out] | this | dcdreader object |
[in] | filename | name of of DCD file to read from |
59 character (len=*),
parameter :: magic_string =
"CORD" 60 integer,
parameter :: magic_number = 84
61 character (len=*),
intent(in) :: filename
62 class(dcdfile),
intent(inout) :: this
63 integer :: line1, charmm_version, has_extra_block, four_dimensions
64 character (len=4) :: line2
68 inquire(file=trim(filename), exist=ex, size=this%filesize)
69 if (ex .eqv. .false.)
then 70 call error_stop_program(trim(filename)//
" does not exist.")
74 open(newunit=this%u, file=trim(filename), form=
"unformatted", access=
"stream")
77 read(this%u,pos=1) line1
81 if (line1 .ne. magic_number .or. line2 .ne. magic_string)
then 85 open(newunit=this%u, file=trim(filename), form=
"unformatted", access=
"stream", convert=
"swap")
87 read(this%u,pos=1) line2
91 if (line1 .ne. magic_number .or. line2 .ne. magic_string)
then 92 call error_stop_program(
"This DCD file format is not supported, or the file header is corrupt.")
98 read(this%u, pos=85) charmm_version
99 if (charmm_version .eq. 0)
then 100 call error_stop_program(
"DCD file indicates it is not CHARMM. Only CHARMM-style DCD files are supported.")
104 read(this%u, pos=49) has_extra_block
105 if (has_extra_block .ne. 1)
then 106 call error_stop_program(
"DCD file indicates it does not have unit cell information. Only DCD files with& 107 & unit cell information are supported.")
111 read(this%u) four_dimensions
112 if (four_dimensions .eq. 1)
then 113 call error_stop_program(
"DCD file indicates it has four dimensions. Only DCD files with three dimensions&
◆ dcdfile_read_header()
subroutine dcdfort_reader::dcdfile_read_header |
( |
class(dcdfile), intent(inout) |
this, |
|
|
integer, intent(out) |
nframes, |
|
|
integer, intent(out) |
istart, |
|
|
integer, intent(out) |
nevery, |
|
|
integer, intent(out) |
iend, |
|
|
real, intent(out) |
timestep, |
|
|
integer, intent(out) |
natoms |
|
) |
| |
Reads header of open DCD file.
Should be called after open()
- Parameters
-
[in,out] | this | dcdreader object |
[in] | nframes | rnumber of frames (snapshots) in file |
[out] | istart | first timestep of trajectory file |
[out] | nevery | how often (in timesteps) file was written to |
[out] | iend | last timestep of trajectory file |
[out] | timestep | timestep of simulation |
[out] | natoms | number of atoms in each snapshot |
132 integer,
intent(out) :: nframes, istart, nevery, iend, natoms
133 integer :: i, ntitle, n, framesize, nframes2, dummy
134 character (len=80) :: title_string
135 real,
intent(out) :: timestep
136 class(dcdfile),
intent(inout) :: this
138 read(this%u, pos=9) nframes, istart, nevery, iend
140 read(this%u, pos=45) timestep
142 read(this%u, pos=97) ntitle
144 write(error_unit,
'(a)') prompt//
"The following titles were found:" 147 read(this%u) title_string
150 do while (n .le. 80 .and. title_string(n:n) .ne. c_null_char)
154 write(error_unit,
'(a)') prompt//
" "//trim(title_string(1:n))
157 read(this%u) dummy, dummy
158 if (dummy .ne. 4)
then 159 call error_stop_program(
"This DCD file format is not supported, or the file header is corrupt.")
163 read(this%u) natoms, dummy
164 if (dummy .ne. 4)
then 165 call error_stop_program(
"This DCD file format is not supported, or the file header is corrupt.")
171 this%framesize = natoms*12 + 80
173 nframes2 = (this%filesize-276)/this%framesize
174 if ( nframes2 .ne. nframes)
then 175 write(error_unit,
'(a,i0,a,i0,a)') prompt//
"WARNING: Header indicates ", nframes, &
176 &
" frames, but file size indicates ", nframes2,
"."
◆ dcdfile_read_next()
subroutine dcdfort_reader::dcdfile_read_next |
( |
class(dcdfile), intent(inout) |
this, |
|
|
real, dimension(:,:), intent(inout), allocatable |
xyz, |
|
|
real(8), dimension(6), intent(inout) |
box |
|
) |
| |
Reads next frame into memory.
- Parameters
-
[in,out] | this | dcdreader object |
[in,out] | xyz | coordinates of all atoms in snapshot. First dimension is atom number, second dimension is x, y, or z !coordinate. |
[in,out] | box | dimensions of snapshot. Array containing 6 elements, ordered as A, B, C, alpha, beta, gamma. A = length of unit cell vector along x-axis; B = length of unit cell vector in xy-plane; C = length of unit cell vector in yz-plane; alpha = cosine of angle between B and C; beta = cosine of angle between A and C; gamma = cosine of angle between A and B; |
208 real,
allocatable,
intent(inout) :: xyz(:,:)
209 real(8),
intent(inout) :: box(6)
211 class(dcdfile),
intent(inout) :: this
214 read(this%u) dummy(1)
217 read(this%u) box(1), box(6), box(2), box(5), box(4), box(3)
220 read(this%u) dummy, xyz(:,1), dummy, xyz(:,2), dummy, xyz(:,3)
222 read(this%u) dummy(1)
◆ dcdfile_skip_next()
subroutine dcdfort_reader::dcdfile_skip_next |
( |
class(dcdfile), intent(inout) |
this, |
|
|
integer, intent(in), optional |
n |
|
) |
| |
Skips reading this frame into memory.
- Parameters
-
[in,out] | this | dcdreader object |
[in] | n | number of frames to skip |
234 integer(8) :: pos, newpos
235 integer,
intent(in),
optional :: n
236 real(8) :: box_dummy(6)
237 class(dcdfile),
intent(inout) :: this
240 inquire(unit=this%u, pos=pos)
243 if (.not.
present(n))
then 244 newpos = pos + this%framesize - 4
246 newpos = pos + this%framesize*n - 4
249 read(this%u, pos=newpos) dummy