Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove symbol length variable #1193

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/io/reader/genformat.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module xtb_io_reader_genformat
use xtb_mctc_accuracy, only : wp
use xtb_mctc_convert
use xtb_mctc_strings
use xtb_mctc_symbols, only : toNumber, symbolLength
use xtb_mctc_symbols, only : toNumber
use xtb_mctc_systools
use xtb_pbc_tools
use xtb_type_molecule
Expand Down
2 changes: 1 addition & 1 deletion src/io/reader/orca.f90
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
module xtb_io_reader_orca
use xtb_mctc_accuracy, only : wp
use xtb_mctc_convert
use xtb_mctc_symbols, only : toNumber, symbolLength
use xtb_mctc_symbols, only : toNumber
use xtb_type_molecule
use xtb_pbc_tools
use xtb_type_reader
Expand Down
2 changes: 1 addition & 1 deletion src/io/reader/turbomole.f90
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ module xtb_io_reader_turbomole
use xtb_mctc_constants
use xtb_mctc_convert
use xtb_mctc_resize
use xtb_mctc_symbols, only : toNumber, symbolLength
use xtb_mctc_symbols, only : toNumber
use xtb_pbc_tools
use xtb_readin, getline => strip_line
use xtb_type_molecule
Expand Down
8 changes: 5 additions & 3 deletions src/mctc/resize.f90
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ end subroutine resizeInt
pure subroutine resizeChar(var, n)

!> TODO
character(len=*), allocatable, intent(inout) :: var(:)
character(len=:), allocatable, intent(inout) :: var(:)

!> TODO
integer, intent(in), optional :: n
Expand All @@ -92,7 +92,8 @@ pure subroutine resizeChar(var, n)
else
length = currentLength + currentLength/2 + 1
endif
allocate(tmp(length), mold=var)
allocate(character(len=len(var)) :: tmp(length))
tmp(:) = repeat(' ', len(var))
tmp(:currentLength) = var(:currentLength)
deallocate(var)
call move_alloc(tmp, var)
Expand All @@ -102,7 +103,8 @@ pure subroutine resizeChar(var, n)
else
length = 64
endif
allocate(var(length), source=' ')
allocate(character(len=80) :: var(length))
var(:) = repeat(' ', 80)
endif

end subroutine resizeChar
Expand Down
13 changes: 4 additions & 9 deletions src/mctc/symbols.f90
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ module xtb_mctc_symbols
implicit none
private

public :: symbolLength
public :: symbolToNumber, numberToSymbol, numberToLcSymbol
public :: toNumber, toSymbol, toLcSymbol, getIdentity

Expand All @@ -33,10 +32,6 @@ module xtb_mctc_symbols
end interface getIdentity


!> Maximum allowed length of element symbols
integer, parameter :: symbolLength = 4


!> Periodic system of elements
character(len=2), parameter :: pse(118) = [ &
& 'H ','He', &
Expand Down Expand Up @@ -246,16 +241,16 @@ subroutine getIdentitySymbol(nId, identity, symbol)
integer, intent(out) :: nId

!> Element symbols
character(len=symbolLength), intent(in) :: symbol(:)
character(len=*), intent(in) :: symbol(:)

!> Chemical identity
integer, intent(out) :: identity(:)

character(len=symbolLength), allocatable :: sTmp(:)
character(len=:), allocatable :: sTmp(:)
integer :: nAt, iAt, iId

nAt = size(identity)
allocate(sTmp(nAt))
allocate(character(len=len(symbol)) :: sTmp(nAt))
nId = 0
do iAt = 1, nAt
iId = findSymbol(sTmp(:nId), symbol(iAt))
Expand Down Expand Up @@ -322,7 +317,7 @@ end function findNumber
pure subroutine appendSymbol(list, nList, symbol)

!> List of element symbols
character(len=*), allocatable, intent(inout) :: list(:)
character(len=:), allocatable, intent(inout) :: list(:)

!> Current occupied size of list
integer, intent(inout) :: nList
Expand Down
7 changes: 3 additions & 4 deletions src/type/identitymap.f90
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
module xtb_type_identitymap
use xtb_mctc_accuracy, only : wp
use xtb_mctc_resize, only : resize
use xtb_mctc_symbols, only : symbolLength
use xtb_type_molecule, only : TMolecule
implicit none
private
Expand All @@ -44,7 +43,7 @@ module xtb_type_identitymap
integer, allocatable :: num(:)

!> Element symbols for each id
character(len=symbolLength), allocatable :: sym(:)
character(len=:), allocatable :: sym(:)

!> Maps from id to its atoms
type(TAtomicMap), allocatable :: map(:)
Expand Down Expand Up @@ -121,7 +120,7 @@ subroutine initIdentityMapFromArrays(self, id, sym, num)
integer, intent(in) :: num(:)

!> Element symbols for each atom
character(len=symbolLength), intent(in) :: sym(:)
character(len=:), allocatable, intent(in) :: sym(:)

integer :: nAt, nId
integer :: iId, iAt, thisAt, initialSize, nMp
Expand All @@ -132,7 +131,7 @@ subroutine initIdentityMapFromArrays(self, id, sym, num)

allocate(self%map(nId))
allocate(self%num(nId))
allocate(self%sym(nId))
allocate(character(len=len(sym)) :: self%sym(nId))

initialSize = nAt / nId + 1
allocate(pos(initialSize))
Expand Down
12 changes: 6 additions & 6 deletions src/type/molecule.f90
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module xtb_type_molecule
use mctc_io_structure, only : structure_type, new_structure
use xtb_mctc_accuracy, only : wp
use xtb_mctc_boundaryconditions, only : boundaryCondition
use xtb_mctc_symbols, only : toNumber, toSymbol, symbolLength, getIdentity
use xtb_mctc_symbols, only : toNumber, toSymbol, getIdentity
use xtb_type_wsc
use xtb_type_topology
use xtb_type_fragments
Expand Down Expand Up @@ -74,7 +74,7 @@ module xtb_type_molecule
integer :: boundaryCondition = boundaryCondition%cluster

!> Element symbols
character(len=symbolLength), allocatable :: sym(:)
character(len=:), allocatable :: sym(:)

!> Ordinal numbers
integer, allocatable :: at(:)
Expand Down Expand Up @@ -224,7 +224,6 @@ end subroutine generate_wsc
logical, intent(in), optional :: pbc(:)

integer, allocatable :: id(:)
character(len=symbolLength), allocatable :: sTmp(:)
integer :: nAt, nId, iAt, iId

nAt = min(size(at, dim=1), size(xyz, dim=2), size(sym, dim=1))
Expand Down Expand Up @@ -297,11 +296,11 @@ subroutine initMoleculeNumbers &
real(wp), intent(in), optional :: lattice(3, 3)
logical, intent(in), optional :: pbc(3)

character(len=4), allocatable :: sym(:)
character(len=:), allocatable :: sym(:)
integer :: nAt

nAt = min(size(at, dim=1), size(xyz, dim=2))
allocate(sym(nAt))
allocate(character(len=len(toSymbol(1))) :: sym(nAt))
sym(:) = toSymbol(at(:nAt))

call init(mol, at, sym, xyz, chrg, uhf, lattice, pbc)
Expand Down Expand Up @@ -467,7 +466,8 @@ subroutine allocate_molecule(self,n)
self%n = n
allocate( self%id(n), source = 0 )
allocate( self%at(n), source = 0 )
allocate( self%sym(n), source = ' ' )
allocate( character(len=80) :: self%sym(n))
self%sym(:) = repeat(' ', 80)
allocate( self%xyz(3,n), source = 0.0_wp )
allocate( self%abc(3,n), source = 0.0_wp )
allocate( self%dist(n,n), source = 0.0_wp )
Expand Down
8 changes: 3 additions & 5 deletions test/unit/test_gfnff.f90
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,6 @@ subroutine test_gfnff_pbc(error)
use xtb_type_data, only : scc_results
use xtb_type_environment, only : TEnvironment, init
use xtb_type_restart, only : TRestart
use xtb_mctc_symbols, only : symbolLength

use xtb_gfnff_calculator, only : TGFFCalculator, newGFFCalculator

Expand All @@ -701,7 +700,7 @@ subroutine test_gfnff_pbc(error)
real(wp), allocatable :: gradient(:, :)
real(wp), allocatable :: xyztmp(:,:), lattmp(:,:)
integer, allocatable :: attmp(:)
character(len=symbolLength), allocatable :: symtmp(:)
character(len=4), allocatable :: symtmp(:)
logical, parameter :: pbc(3) = [.true., .true., .true. ]
! structures from X23, mcVOL22, and GFN-FF for Ln/An paper
character(len=*), parameter :: pbc_strucs(3) = [&
Expand Down Expand Up @@ -840,7 +839,7 @@ subroutine test_gfnff_pbc(error)
allocate(symtmp(2*mol%n))
symtmp = mol%sym
deallocate(mol%sym)
allocate(mol%sym(2*mol%n))
allocate(character(len=len(symtmp)) :: mol%sym(2*mol%n))
mol%sym(1:mol%n)= symtmp
mol%sym(mol%n+1:2*mol%n) = symtmp
! lattice
Expand Down Expand Up @@ -889,7 +888,6 @@ subroutine test_gfnff_LnAn_H(error)
use xtb_type_data, only : scc_results
use xtb_type_environment, only : TEnvironment, init
use xtb_type_restart, only : TRestart
use xtb_mctc_symbols, only : symbolLength

use xtb_gfnff_calculator, only : TGFFCalculator, newGFFCalculator

Expand All @@ -911,7 +909,7 @@ subroutine test_gfnff_LnAn_H(error)
real(wp), allocatable :: gradient(:, :)
real(wp), allocatable :: xyztmp(:,:), lattmp(:,:)
integer, allocatable :: attmp(:)
character(len=symbolLength), allocatable :: symtmp(:)
character(len=4), allocatable :: symtmp(:)
logical, parameter :: pbc(3) = [.true., .true., .true. ]
! structures from X23, mcVOL22, and GFN-FF for Ln/An paper
character(len=*), parameter :: struc(1) = ["Ce_0a7745"]
Expand Down