assign_pitors Subroutine

public subroutine assign_pitors(bds, prm_buf)

Uses

  • proc~~assign_pitors~~UsesGraph proc~assign_pitors assign_pitors module~mod_bonded mod_bonded proc~assign_pitors->module~mod_bonded module~mod_memory mod_memory proc~assign_pitors->module~mod_memory module~mod_constants mod_constants proc~assign_pitors->module~mod_constants module~mod_bonded->module~mod_memory module~mod_io mod_io module~mod_bonded->module~mod_io module~mod_topology mod_topology module~mod_bonded->module~mod_topology module~mod_memory->module~mod_constants module~mod_memory->module~mod_io iso_c_binding iso_c_binding module~mod_memory->iso_c_binding module~mod_constants->iso_c_binding module~mod_io->module~mod_constants module~mod_topology->module~mod_memory module~mod_adjacency_mat mod_adjacency_mat module~mod_topology->module~mod_adjacency_mat 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_pitors~~CallsGraph proc~assign_pitors assign_pitors proc~read_atom_cards read_atom_cards proc~assign_pitors->proc~read_atom_cards proc~tokenize tokenize proc~assign_pitors->proc~tokenize interface~mallocate mallocate proc~assign_pitors->interface~mallocate proc~isint isint proc~assign_pitors->proc~isint proc~fatal_error fatal_error proc~assign_pitors->proc~fatal_error proc~isreal isreal proc~assign_pitors->proc~isreal proc~pitors_init pitors_init proc~assign_pitors->proc~pitors_init interface~mfree mfree proc~assign_pitors->interface~mfree proc~read_atom_cards->proc~tokenize proc~read_atom_cards->interface~mallocate 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~r_alloc1 r_alloc1 interface~mallocate->proc~r_alloc1 proc~r_alloc3 r_alloc3 interface~mallocate->proc~r_alloc3 proc~i_alloc2 i_alloc2 interface~mallocate->proc~i_alloc2 proc~i_alloc3 i_alloc3 interface~mallocate->proc~i_alloc3 proc~l_alloc2 l_alloc2 interface~mallocate->proc~l_alloc2 proc~i_alloc1 i_alloc1 interface~mallocate->proc~i_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~pitors_init->interface~mallocate proc~r_free1 r_free1 interface~mfree->proc~r_free1 proc~i_free3 i_free3 interface~mfree->proc~i_free3 proc~i_free1 i_free1 interface~mfree->proc~i_free1 proc~i_free2 i_free2 interface~mfree->proc~i_free2 proc~l_free2 l_free2 interface~mfree->proc~l_free2 proc~l_free1 l_free1 interface~mfree->proc~l_free1 proc~r_free3 r_free3 interface~mfree->proc~r_free3 proc~r_free2 r_free2 interface~mfree->proc~r_free2 proc~chk_free chk_free proc~r_free1->proc~chk_free proc~i_free3->proc~chk_free proc~chk_alloc chk_alloc proc~r_alloc1->proc~chk_alloc proc~memory_init memory_init proc~r_alloc1->proc~memory_init 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~i_alloc3->proc~chk_alloc proc~i_alloc3->proc~memory_init proc~l_alloc2->proc~chk_alloc proc~l_alloc2->proc~memory_init proc~i_free1->proc~chk_free proc~i_free2->proc~chk_free proc~l_free2->proc~chk_free proc~l_free1->proc~chk_free proc~i_alloc1->proc~chk_alloc proc~i_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~close_output->proc~ommp_message proc~r_free3->proc~chk_free proc~r_free2->proc~chk_free proc~chk_free->proc~fatal_error proc~chk_alloc->proc~fatal_error

Called by

proc~~assign_pitors~~CalledByGraph proc~assign_pitors assign_pitors proc~mmpol_init_from_xyz mmpol_init_from_xyz proc~mmpol_init_from_xyz->proc~assign_pitors proc~ommp_system_from_qm_helper ommp_system_from_qm_helper proc~ommp_system_from_qm_helper->proc~assign_pitors proc~ommp_init_xyz ommp_init_xyz proc~ommp_init_xyz->proc~mmpol_init_from_xyz program~test_si_geomgrad test_SI_geomgrad program~test_si_geomgrad->proc~ommp_system_from_qm_helper program~test_si_geomgrad_num test_SI_geomgrad_num program~test_si_geomgrad_num->proc~ommp_system_from_qm_helper 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_pitors(bds, prm_buf)
        use mod_memory, only: mallocate, mfree
        use mod_bonded, only: pitors_init
        use mod_constants, only: kcalmol2au
        
        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, tokb, toke, ipitors, npitors, &
                       cla, clb, maxpi, a, b, c, jb, iprm
        character(len=OMMP_STR_CHAR_MAX) :: line, errstring
        integer(ip), allocatable :: classa(:), classb(:), tmpat(:,:)
        real(rp), allocatable :: kpi(:), tmpk(:)
        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
        npitors = 1
        do il=1, size(prm_buf) 
            line = prm_buf(il)
            if(line(:7) == 'pitors ') npitors = npitors + 1
        end do

        maxpi = top%mm_atoms 
        ! TODO This is maybe excessive, all trivalent atomso should be enough
        call mallocate('assign_pitors [classa]', npitors, classa)
        call mallocate('assign_pitors [classb]', npitors, classb)
        call mallocate('assign_pitors [kpi]', npitors, kpi)
        call mallocate('assign_pitors [tmpat]', 6, maxpi, tmpat)
        call mallocate('assign_pitors [tmpk]', maxpi, tmpk)

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

                tokb = toke + 1
                toke = tokenize(line, tokb)
                if(.not. isint(line(tokb:toke))) then
                    write(errstring, *) "Wrong PITORS card"
                    call fatal_error(errstring)
                end if
                read(line(tokb:toke), *) classb(ipitors)
                
                tokb = toke + 1
                toke = tokenize(line, tokb)
                if(.not. isreal(line(tokb:toke))) then
                    write(errstring, *) "Wrong PITORS card"
                    call fatal_error(errstring)
                end if
                read(line(tokb:toke), *) kpi(ipitors)
                
                ipitors = ipitors + 1
            end if
            i = i+1
        end do
       
        ipitors = 1
        do a=1, top%mm_atoms
            ! Check if the center is trigonal
            if(top%conn(1)%ri(a+1) - top%conn(1)%ri(a) /= 3) cycle
            cla = top%atclass(a)
            ! Loop over the atoms connected to the trignonal center
            do jb=top%conn(1)%ri(a), top%conn(1)%ri(a+1)-1
                b = top%conn(1)%ci(jb)
                ! This avoid to compute the functions two times
                if(a > b) cycle
                
                !Check if the second center is trigonal
                if(top%conn(1)%ri(b+1) - top%conn(1)%ri(b) /= 3) cycle
                clb = top%atclass(b)

                do iprm=1, npitors
                    if((cla == classa(iprm) .and. clb == classb(iprm)) .or. &
                       (clb == classa(iprm) .and. cla == classb(iprm))) then
                        ! The parameter is the right one
                        ! Save the atoms in the following way:
                        !
                        !  2        5            a => 1
                        !   \      /             b => 4
                        !    1 -- 4  
                        !   /      \
                        !  3        6
                        
                        tmpat(:,ipitors) = 0
                        tmpat(1,ipitors) = a
                        do i=top%conn(1)%ri(a), top%conn(1)%ri(a+1)-1
                            c = top%conn(1)%ci(i)
                            if(c /= b) then
                                if(tmpat(2,ipitors) == 0) then
                                    tmpat(2,ipitors) = c
                                else
                                    tmpat(3,ipitors) = c
                                end if
                            end if
                        end do

                        tmpat(4,ipitors) = b
                        do i=top%conn(1)%ri(b), top%conn(1)%ri(b+1)-1
                            c = top%conn(1)%ci(i)
                            if(c /= a) then
                                if(tmpat(5,ipitors) == 0) then
                                    tmpat(5,ipitors) = c
                                else
                                    tmpat(6,ipitors) = c
                                end if
                            end if
                        end do
                        tmpk(ipitors) = kpi(iprm)
                        
                        ipitors = ipitors+1
                        exit
                    end if
                end do
            end do
        end do
        
        call pitors_init(bds, ipitors-1)
        
        do i=1, ipitors-1
            bds%kpitors(i) = tmpk(i) * kcalmol2au
            bds%pitorsat(:,i) = tmpat(:,i)
        end do

        call mfree('assign_pitors [classa]', classa)
        call mfree('assign_pitors [classb]', classb)
        call mfree('assign_pitors [kpi]', kpi)
        call mfree('assign_pitors [tmpat]', tmpat)
        call mfree('assign_pitors [tmpk]', tmpk)
    
    end subroutine assign_pitors