107 CHARACTER(len=*),
PARAMETER :: routinen =
'read_coordinate_pdb'
108 INTEGER,
PARAMETER :: nblock = 1000
110 CHARACTER(LEN=default_path_length) :: line
111 CHARACTER(LEN=default_string_length) :: record, root_mol_name, strtmp
112 INTEGER :: handle, id0, inum_mol, istat, iw, natom, &
115 REAL(kind=
dp) :: pfactor
123 extension=
".subsysLog")
124 CALL timeset(routinen, handle)
126 pfactor =
section_get_rval(subsys_section,
"TOPOLOGY%MEMORY_PROGRESSION_FACTOR")
128 CALL reallocate(atom_info%id_molname, 1, nblock)
129 CALL reallocate(atom_info%id_resname, 1, nblock)
131 CALL reallocate(atom_info%id_atmname, 1, nblock)
133 CALL reallocate(atom_info%atm_mass, 1, nblock)
134 CALL reallocate(atom_info%atm_charge, 1, nblock)
137 CALL reallocate(atom_info%id_element, 1, nblock)
140 WRITE (unit=iw, fmt=
"(T2,A)") &
141 "BEGIN of PDB data read from file "//trim(
topology%coord_file_name)
145 topology%molname_generated = .false.
151 WRITE (unit=root_mol_name, fmt=
'(A3,I0)')
"MOL", inum_mol
158 record = trim(record)
160 IF ((record ==
"ATOM") .OR. (record ==
"HETATM"))
THEN
163 IF (natom >
SIZE(atom_info%id_atmname))
THEN
164 newsize = int(pfactor*natom)
165 CALL reallocate(atom_info%id_molname, 1, newsize)
166 CALL reallocate(atom_info%id_resname, 1, newsize)
168 CALL reallocate(atom_info%id_atmname, 1, newsize)
169 CALL reallocate(atom_info%r, 1, 3, 1, newsize)
170 CALL reallocate(atom_info%atm_mass, 1, newsize)
171 CALL reallocate(atom_info%atm_charge, 1, newsize)
174 CALL reallocate(atom_info%id_element, 1, newsize)
179 CASE (
"ATOM",
"HETATM")
180 READ (unit=line(13:16), fmt=*) strtmp
181 atom_info%id_atmname(natom) =
str2id(
s2s(strtmp))
182 READ (unit=line(18:20), fmt=*, iostat=istat) strtmp
184 atom_info%id_resname(natom) =
str2id(
s2s(strtmp))
186 atom_info%id_resname(natom) = id0
188 READ (unit=line(23:26), fmt=*, iostat=istat) atom_info%resid(natom)
189 READ (unit=line(31:38), fmt=*, iostat=istat) atom_info%r(1, natom)
190 READ (unit=line(39:46), fmt=*, iostat=istat) atom_info%r(2, natom)
191 READ (unit=line(47:54), fmt=*, iostat=istat) atom_info%r(3, natom)
192 READ (unit=line(55:60), fmt=*, iostat=istat) atom_info%occup(natom)
193 READ (unit=line(61:66), fmt=*, iostat=istat) atom_info%beta(natom)
194 READ (unit=line(73:76), fmt=*, iostat=istat) strtmp
196 atom_info%id_molname(natom) =
str2id(
s2s(strtmp))
198 atom_info%id_molname(natom) =
str2id(
s2s(root_mol_name))
201 READ (unit=line(77:78), fmt=*, iostat=istat) strtmp
203 atom_info%id_element(natom) =
str2id(
s2s(strtmp))
205 atom_info%id_element(natom) = id0
207 atom_info%atm_mass(natom) = 0.0_dp
208 atom_info%atm_charge(natom) = -huge(0.0_dp)
209 IF (
topology%charge_occup) atom_info%atm_charge(natom) = atom_info%occup(natom)
210 IF (
topology%charge_beta) atom_info%atm_charge(natom) = atom_info%beta(natom)
212 READ (unit=line(81:), fmt=*, iostat=istat) atom_info%atm_charge(natom)
215 IF (atom_info%id_element(natom) == id0)
THEN
218 atom_info%id_element(natom) = atom_info%id_atmname(natom)
222 WRITE (unit=iw, fmt=
"(A6,I5,T13,A4,T18,A3,T23,I4,T31,3F8.3,T73,A4,T77,A2)") &
224 trim(
id2str(atom_info%id_atmname(natom))), &
225 trim(
id2str(atom_info%id_resname(natom))), &
226 atom_info%resid(natom), &
227 atom_info%r(1, natom), &
228 atom_info%r(2, natom), &
229 atom_info%r(3, natom), &
230 adjustl(trim(
id2str(atom_info%id_molname(natom)))), &
231 adjustr(trim(
id2str(atom_info%id_element(natom))))
233 atom_info%r(1, natom) =
cp_unit_to_cp2k(atom_info%r(1, natom),
"angstrom")
234 atom_info%r(2, natom) =
cp_unit_to_cp2k(atom_info%r(2, natom),
"angstrom")
235 atom_info%r(3, natom) =
cp_unit_to_cp2k(atom_info%r(3, natom),
"angstrom")
237 inum_mol = inum_mol + 1
238 WRITE (unit=root_mol_name, fmt=
'(A3,I0)')
"MOL", inum_mol
240 IF (iw > 0)
WRITE (unit=iw, fmt=*) trim(line)
248 CALL reallocate(atom_info%id_molname, 1, natom)
249 CALL reallocate(atom_info%id_resname, 1, natom)
251 CALL reallocate(atom_info%id_atmname, 1, natom)
254 CALL reallocate(atom_info%atm_charge, 1, natom)
257 CALL reallocate(atom_info%id_element, 1, natom)
260 IF (.NOT.
topology%para_res) atom_info%resid(:) = 1
264 WRITE (unit=iw, fmt=
"(T2,A)") &
265 "END of PDB data read from file "//trim(
topology%coord_file_name)
270 "PRINT%TOPOLOGY_INFO/PDB_INFO")
271 CALL timestop(handle)
283 INTEGER,
INTENT(IN) :: file_unit
287 CHARACTER(len=*),
PARAMETER :: routinen =
'write_coordinate_pdb'
289 CHARACTER(LEN=120) :: line
290 CHARACTER(LEN=default_path_length) :: record
291 CHARACTER(LEN=default_string_length) :: my_tag1, my_tag2, my_tag3, my_tag4
292 CHARACTER(LEN=timestamp_length) :: timestamp
293 INTEGER :: handle, i, id1, id2, idres, iw, natom
294 LOGICAL :: charge_beta, charge_extended, &
296 REAL(kind=
dp) :: angle_alpha, angle_beta, angle_gamma
297 REAL(kind=
dp),
DIMENSION(3) :: abc
305 extension=
".subsysLog")
307 CALL timeset(routinen, handle)
312 i = count((/charge_occup, charge_beta, charge_extended/))
314 cpabort(
"Either only CHARGE_OCCUP, CHARGE_BETA, or CHARGE_EXTENDED can be selected")
321 IF (iw > 0)
WRITE (unit=iw, fmt=*)
" Writing out PDB file ", trim(record)
325 WRITE (unit=file_unit, fmt=
"(A6,T11,A)") &
330 WRITE (unit=file_unit, fmt=
"(A6,3F9.3,3F7.2)") &
331 "CRYST1", abc(1:3)*
angstrom, angle_alpha, angle_beta, angle_gamma
341 idres = atom_info%resid(i)
343 IF ((id1 /= atom_info%map_mol_num(i)) .OR. (id2 /= atom_info%map_mol_typ(i)))
THEN
345 id1 = atom_info%map_mol_num(i)
346 id2 = atom_info%map_mol_typ(i)
356 WRITE (unit=line(1:6), fmt=
"(A6)")
"ATOM "
357 WRITE (unit=line(7:11), fmt=
"(I5)")
modulo(i, 100000)
358 WRITE (unit=line(13:16), fmt=
"(A4)") adjustl(my_tag1(1:4))
359 WRITE (unit=line(18:20), fmt=
"(A3)") trim(my_tag2)
360 WRITE (unit=line(23:26), fmt=
"(I4)")
modulo(idres, 10000)
361 WRITE (unit=line(31:54), fmt=
"(3F8.3)") atom_info%r(1:3, i)*
angstrom
362 IF (
ASSOCIATED(atom_info%occup))
THEN
363 WRITE (unit=line(55:60), fmt=
"(F6.2)") atom_info%occup(i)
365 WRITE (unit=line(55:60), fmt=
"(F6.2)") 0.0_dp
367 IF (
ASSOCIATED(atom_info%beta))
THEN
368 WRITE (unit=line(61:66), fmt=
"(F6.2)") atom_info%beta(i)
370 WRITE (unit=line(61:66), fmt=
"(F6.2)") 0.0_dp
372 IF (
ASSOCIATED(atom_info%atm_charge))
THEN
373 IF (any((/charge_occup, charge_beta, charge_extended/)) .AND. &
374 (atom_info%atm_charge(i) == -huge(0.0_dp))) &
375 cpabort(
"No atomic charges found yet (after the topology setup)")
376 IF (charge_occup)
THEN
377 WRITE (unit=line(55:60), fmt=
"(F6.2)") atom_info%atm_charge(i)
378 ELSE IF (charge_beta)
THEN
379 WRITE (unit=line(61:66), fmt=
"(F6.2)") atom_info%atm_charge(i)
380 ELSE IF (charge_extended)
THEN
381 WRITE (unit=line(81:), fmt=
"(F20.16)") atom_info%atm_charge(i)
386 WRITE (unit=line(73:76), fmt=
"(A4)") adjustl(my_tag3)
387 WRITE (unit=line(77:78), fmt=
"(A2)") trim(my_tag4)
388 WRITE (unit=file_unit, fmt=
"(A)") trim(line)
390 WRITE (unit=file_unit, fmt=
"(A3)")
"END"
392 IF (iw > 0)
WRITE (unit=iw, fmt=*)
" Exiting "//routinen
395 "PRINT%TOPOLOGY_INFO/PDB_INFO")
397 CALL timestop(handle)