Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(ommp_topology_type), | intent(inout) | :: | top |
Topology object |
||
character(len=OMMP_STR_CHAR_MAX), | intent(in) | :: | prm_buf(:) |
subroutine read_atom_cards(top, prm_buf)
use mod_memory, only: mallocate, mfree
use mod_io, only: fatal_error
implicit none
type(ommp_topology_type), intent(inout) :: top
!! Topology object
character(len=OMMP_STR_CHAR_MAX), intent(in) :: prm_buf(:)
integer(ip) :: i, il, lc, iat, toke, tokb, tokb1, nquote
character(len=OMMP_STR_CHAR_MAX) :: line, errstring
integer(ip) :: natype
integer(ip), allocatable, dimension(:) :: typez, typeclass
real(rp), allocatable, dimension(:) :: typemass
if(.not. top%attype_initialized) then
call fatal_error("Atom type array in topology should be initialized&
& before performing atomclass asignament.")
end if
! Read all the lines of file just to count how large vector should be
! allocated
natype = 0
do il=1, size(prm_buf)
line = prm_buf(il)
if(line(:5) == 'atom ') then
tokb = 6
toke = tokenize(line, tokb)
if(.not. isint(line(tokb:toke))) then
write(errstring, *) "Wrong ATOM card"
call fatal_error(errstring)
end if
read(line(tokb:toke), *) iat
natype = max(natype, iat)
end if
end do
call mallocate('read_prm [typeclass]', natype, typeclass)
call mallocate('read_prm [typez]', natype, typez)
call mallocate('read_prm [typemass]', natype, typemass)
typeclass = 0
typez = 0
typemass = 0.0
! Restart the reading from the beginning to actually save the parameters
do il=1, size(prm_buf)
line = prm_buf(il)
if(line(:5) == 'atom ') then
tokb = 6
toke = tokenize(line, tokb)
if(.not. isint(line(tokb:toke))) then
write(errstring, *) "Wrong ATOM card"
call fatal_error(errstring)
end if
read(line(tokb:toke), *) iat
tokb = toke+1
toke = tokenize(line, tokb)
read(line(tokb:toke), *) typeclass(iat)
tokb = toke+1
toke = tokenize(line, tokb)
! This token contain the atom name
tokb = toke+1
toke = tokenize(line, tokb)
nquote = count_substr_occurence(line(tokb:toke), '"')
do while(nquote < 2)
tokb1 = toke+1
toke = tokenize(line, tokb1)
nquote = nquote + count_substr_occurence(line(tokb1:toke), '"')
end do
! This token contains the description string
tokb = toke+1
toke = tokenize(line, tokb)
read(line(tokb:toke), *) typez(iat)
tokb = toke+1
toke = tokenize(line, tokb)
read(line(tokb:toke), *) typemass(iat)
! Only partial reading of ATOM card is needed for now.
end if
end do
!$omp parallel do
do i = 1, top%mm_atoms
if(.not. top%atclass_initialized) then
top%atclass(i) = typeclass(top%attype(i))
end if
if(.not. top%atz_initialized) then
top%atz(i) = typez(top%attype(i))
end if
if(.not. top%atmass_initialized) then
top%atmass(i) = typemass(top%attype(i))
end if
end do
top%atclass_initialized = .true.
top%atz_initialized = .true.
top%atmass_initialized = .true.
call mfree('read_prm [typeclass]', typeclass)
call mfree('read_prm [typez]', typez)
call mfree('read_prm [typemass]', typemass)
end subroutine read_atom_cards