assign_strtor Subroutine

public subroutine assign_strtor(bds, prm_buf)

Uses

  • proc~~assign_strtor~~UsesGraph proc~assign_strtor assign_strtor module~mod_bonded mod_bonded proc~assign_strtor->module~mod_bonded module~mod_constants mod_constants proc~assign_strtor->module~mod_constants module~mod_memory mod_memory proc~assign_strtor->module~mod_memory module~mod_bonded->module~mod_memory module~mod_topology mod_topology module~mod_bonded->module~mod_topology module~mod_io mod_io module~mod_bonded->module~mod_io iso_c_binding iso_c_binding module~mod_constants->iso_c_binding module~mod_memory->module~mod_constants module~mod_memory->iso_c_binding module~mod_memory->module~mod_io module~mod_topology->module~mod_memory module~mod_adjacency_mat mod_adjacency_mat module~mod_topology->module~mod_adjacency_mat module~mod_io->module~mod_constants module~mod_adjacency_mat->module~mod_memory

Arguments

Type IntentOptional Attributes Name
type(ommp_bonded_type), intent(inout) :: bds

Bonded potential data structure

character(len=OMMP_STR_CHAR_MAX), intent(in) :: prm_buf(:)

Calls

proc~~assign_strtor~~CallsGraph proc~assign_strtor assign_strtor proc~read_atom_cards read_atom_cards proc~assign_strtor->proc~read_atom_cards interface~mallocate mallocate proc~assign_strtor->interface~mallocate proc~tokenize tokenize proc~assign_strtor->proc~tokenize proc~isint isint proc~assign_strtor->proc~isint proc~fatal_error fatal_error proc~assign_strtor->proc~fatal_error proc~isreal isreal proc~assign_strtor->proc~isreal proc~strtor_init strtor_init proc~assign_strtor->proc~strtor_init interface~mfree mfree proc~assign_strtor->interface~mfree proc~read_atom_cards->interface~mallocate proc~read_atom_cards->proc~tokenize proc~read_atom_cards->proc~isint proc~read_atom_cards->proc~fatal_error proc~read_atom_cards->interface~mfree proc~count_substr_occurence count_substr_occurence proc~read_atom_cards->proc~count_substr_occurence proc~i_alloc1 i_alloc1 interface~mallocate->proc~i_alloc1 proc~i_alloc3 i_alloc3 interface~mallocate->proc~i_alloc3 proc~l_alloc2 l_alloc2 interface~mallocate->proc~l_alloc2 proc~r_alloc3 r_alloc3 interface~mallocate->proc~r_alloc3 proc~i_alloc2 i_alloc2 interface~mallocate->proc~i_alloc2 proc~r_alloc1 r_alloc1 interface~mallocate->proc~r_alloc1 proc~r_alloc2 r_alloc2 interface~mallocate->proc~r_alloc2 proc~l_alloc1 l_alloc1 interface~mallocate->proc~l_alloc1 proc~ommp_message ommp_message proc~fatal_error->proc~ommp_message proc~close_output close_output proc~fatal_error->proc~close_output proc~strtor_init->interface~mallocate proc~l_free1 l_free1 interface~mfree->proc~l_free1 proc~i_free2 i_free2 interface~mfree->proc~i_free2 proc~r_free3 r_free3 interface~mfree->proc~r_free3 proc~r_free2 r_free2 interface~mfree->proc~r_free2 proc~i_free1 i_free1 interface~mfree->proc~i_free1 proc~r_free1 r_free1 interface~mfree->proc~r_free1 proc~l_free2 l_free2 interface~mfree->proc~l_free2 proc~i_free3 i_free3 interface~mfree->proc~i_free3 proc~chk_free chk_free proc~l_free1->proc~chk_free proc~i_free2->proc~chk_free proc~r_free3->proc~chk_free proc~chk_alloc chk_alloc proc~i_alloc1->proc~chk_alloc proc~memory_init memory_init proc~i_alloc1->proc~memory_init proc~i_alloc3->proc~chk_alloc proc~i_alloc3->proc~memory_init proc~l_alloc2->proc~chk_alloc proc~l_alloc2->proc~memory_init proc~r_free2->proc~chk_free proc~close_output->proc~ommp_message proc~i_free1->proc~chk_free proc~r_free1->proc~chk_free proc~r_alloc3->proc~chk_alloc proc~r_alloc3->proc~memory_init proc~i_alloc2->proc~chk_alloc proc~i_alloc2->proc~memory_init proc~r_alloc1->proc~chk_alloc proc~r_alloc1->proc~memory_init proc~r_alloc2->proc~chk_alloc proc~r_alloc2->proc~memory_init proc~l_alloc1->proc~chk_alloc proc~l_alloc1->proc~memory_init proc~l_free2->proc~chk_free proc~i_free3->proc~chk_free proc~chk_free->proc~fatal_error proc~chk_alloc->proc~fatal_error

Called by

proc~~assign_strtor~~CalledByGraph proc~assign_strtor assign_strtor proc~mmpol_init_from_xyz mmpol_init_from_xyz proc~mmpol_init_from_xyz->proc~assign_strtor proc~ommp_system_from_qm_helper ommp_system_from_qm_helper proc~ommp_system_from_qm_helper->proc~assign_strtor proc~ommp_init_xyz ommp_init_xyz proc~ommp_init_xyz->proc~mmpol_init_from_xyz proc~c_ommp_system_from_qm_helper C_ommp_system_from_qm_helper proc~c_ommp_system_from_qm_helper->proc~ommp_system_from_qm_helper proc~c_ommp_init_xyz C_ommp_init_xyz proc~c_ommp_init_xyz->proc~ommp_init_xyz

Contents

Source Code


Source Code

    subroutine assign_strtor(bds, prm_buf)
        use mod_memory, only: mallocate, mfree
        use mod_bonded, only: strtor_init
        use mod_constants, only: kcalmol2au, angstrom2au
        
        implicit none
        
        type(ommp_bonded_type), intent(inout) :: bds
        !! Bonded potential data structure
        character(len=OMMP_STR_CHAR_MAX), intent(in) :: prm_buf(:)

        integer(ip) :: il, i, j, tokb, toke, it, nt, &
                       cla, clb, clc, cld, maxt, a, b, c, d, jb, jc, jd, iprm
        character(len=OMMP_STR_CHAR_MAX) :: line, errstring
        integer(ip), allocatable :: classa(:), classb(:), classc(:), classd(:), &
                                    tmpat(:,:), tmpprm(:)
        real(rp), allocatable :: kat(:,:)
        logical :: tor_done, bnd1_done, bnd2_done, bnd3_done
        type(ommp_topology_type), pointer :: top

        top => bds%top

        if(.not. top%atclass_initialized .or. .not. top%atz_initialized) then
            call read_atom_cards(top, prm_buf)
        end if
        
        
        ! Read all the lines of file just to count how large vector should be 
        ! allocated
        nt = 1
        do il=1, size(prm_buf) 
            line = prm_buf(il)
            if(line(:8) == 'strtors ') nt = nt + 1
        end do

        maxt = top%conn(4)%ri(top%mm_atoms+1)-1 
        call mallocate('assign_strtor [classa]', nt, classa)
        call mallocate('assign_strtor [classb]', nt, classb)
        call mallocate('assign_strtor [classc]', nt, classc)
        call mallocate('assign_strtor [classd]', nt, classd)
        call mallocate('assign_strtor [kat]', 9_ip, nt, kat)
        call mallocate('assign_strtor [tmpat]', 4_ip, maxt, tmpat)
        call mallocate('assign_strtor [tmpprm]', maxt, tmpprm)

        ! Restart the reading from the beginning to actually save the parameters
        it = 1
        i=1
        do il=1, size(prm_buf) 
            line = prm_buf(il)
           
            if(line(:8) == 'strtors ') then
                tokb = 9
                toke = tokenize(line, tokb)
                if(.not. isint(line(tokb:toke))) then
                    write(errstring, *) "Wrong STRTORS card"
                    call fatal_error(errstring)
                end if
                read(line(tokb:toke), *) classa(it)

                tokb = toke + 1
                toke = tokenize(line, tokb)
                if(.not. isint(line(tokb:toke))) then
                    write(errstring, *) "Wrong STRTORS card"
                    call fatal_error(errstring)
                end if
                read(line(tokb:toke), *) classb(it)

                tokb = toke + 1
                toke = tokenize(line, tokb)
                if(.not. isint(line(tokb:toke))) then
                    write(errstring, *) "Wrong STRTORS card"
                    call fatal_error(errstring)
                end if
                read(line(tokb:toke), *) classc(it)

                tokb = toke + 1
                toke = tokenize(line, tokb)
                if(.not. isint(line(tokb:toke))) then
                    write(errstring, *) "Wrong STRTORS card"
                    call fatal_error(errstring)
                end if
                read(line(tokb:toke), *) classd(it)
                
                do j=1, 9
                    tokb = toke + 1
                    toke = tokenize(line, tokb)

                    if(.not. isreal(line(tokb:toke))) then
                        write(errstring, *) "Wrong STRTORS card"
                        call fatal_error(errstring)
                    end if
                    read(line(tokb:toke), *) kat(j,it)
                end do

                it = it + 1
            end if
            i = i+1
        end do

        it = 1
        do a=1, top%mm_atoms
            cla = top%atclass(a)
            do jb=top%conn(1)%ri(a), top%conn(1)%ri(a+1)-1
                b = top%conn(1)%ci(jb)
                clb = top%atclass(b)
                do jc=top%conn(1)%ri(b), top%conn(1)%ri(b+1)-1
                    c = top%conn(1)%ci(jc)
                    if(c == a) cycle
                    clc = top%atclass(c)
                    do jd=top%conn(1)%ri(c), top%conn(1)%ri(c+1)-1
                        d = top%conn(1)%ci(jd)
                        if(d == a .or. d == b) cycle
                        if(a > d) cycle
                        cld = top%atclass(d)
                        ! There is a dihedral A-B-C-D
                        do iprm=1, nt
                            if((classa(iprm) == cla .and. &
                                classb(iprm) == clb .and. &
                                classc(iprm) == clc .and. &
                                classd(iprm) == cld) .or. &
                               (classa(iprm) == cld .and. &
                                classb(iprm) == clc .and. &
                                classc(iprm) == clb .and. &
                                 classd(iprm) == cla)) then
                                ! The parameter is ok
                                tmpat(:,it) = [a, b, c, d]
                                tmpprm(it) = iprm
                                it = it+1
                                exit
                            end if
                        end do
                    end do
                end do
            end do
        end do

        call strtor_init(bds, it-1)
        do i=1, it-1
            bds%strtorat(:,i) = tmpat(:,i) 
            if(classa(tmpprm(i)) == top%atclass(bds%strtorat(1,i))) then
                bds%strtork(:,i) = kat(:,tmpprm(i))
            else
                bds%strtork(1:3,i) = kat(7:9,tmpprm(i))
                bds%strtork(4:6,i) = kat(4:6,tmpprm(i))
                bds%strtork(7:9,i) = kat(1:3,tmpprm(i))
            end if
            bds%strtork(:,i) = bds%strtork(:,i) * kcalmol2au / angstrom2au

            tor_done = .false.
            do j=1, size(bds%torsionat, 2)
                if(all(bds%strtorat(:,i) == bds%torsionat(:,j))) then
                    tor_done = .true.
                    bds%strtor_t(i) = j
                    exit
                end if
            end do
            
            bnd1_done = .false.
            bnd2_done = .false.
            bnd3_done = .false.
            do j=1, size(bds%bondat, 2)
                if(all(bds%strtorat(1:2,i) == bds%bondat(:,j)) .or. &
                   all(bds%strtorat(2:1:-1,i) == bds%bondat(:,j))) then
                    bnd1_done = .true.
                    bds%strtor_b(1,i) = j
                else if(all(bds%strtorat(2:3,i) == bds%bondat(:,j)) .or. &
                        all(bds%strtorat(3:2:-1,i) == bds%bondat(:,j))) then
                    bnd2_done = .true.
                    bds%strtor_b(2,i) = j
                else if(all(bds%strtorat(3:4,i) == bds%bondat(:,j)) .or. &
                        all(bds%strtorat(4:3:-1,i) == bds%bondat(:,j))) then
                    bnd3_done = .true.
                    bds%strtor_b(3,i) = j
                end if
                if(bnd1_done .and. bnd2_done .and. bnd3_done) exit
            end do

            if(.not. (tor_done .and. bnd1_done .and. bnd2_done .and. bnd3_done)) then
                call fatal_error('Ill defined stretching-torsion coupling parameter')
            end if
        end do
        
        call mfree('assign_strtor [classa]', classa)
        call mfree('assign_strtor [classb]', classb)
        call mfree('assign_strtor [classc]', classc)
        call mfree('assign_strtor [classd]', classd)
        call mfree('assign_strtor [kat]', kat)
        call mfree('assign_strtor [tmpat]', tmpat)
        call mfree('assign_strtor [tmpprm]', tmpprm)
       
    end subroutine assign_strtor