Skip to content

Commit

Permalink
protect against phonopy yaml file with no eigenvector data
Browse files Browse the repository at this point in the history
  • Loading branch information
aoterodelaroza committed Aug 27, 2024
1 parent b15424a commit dc7bb4b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.256
1.2.257
20 changes: 16 additions & 4 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -561,13 +561,15 @@ subroutine read_phonopy_yaml(c,vib,file,errmsg,ti)
character(len=:), allocatable, intent(out) :: errmsg
type(thread_info), intent(in), optional :: ti

logical :: ok
logical :: ok, readvec
character(len=:), allocatable :: line
integer :: lu, idx, i, j, ifreq
real*8 :: xdum(2)
real*8 :: xdum(2), norm
! integer :: jfreq, iqpt ! checking normalization
! complex*16 :: summ

real*8, parameter :: eps_error = 1d-100

! initialize
errmsg = "Error reading yaml file: " // trim(file)
lu = -1
Expand Down Expand Up @@ -610,6 +612,7 @@ subroutine read_phonopy_yaml(c,vib,file,errmsg,ti)
! - # atom 1
! - [ 0.00451257038677, 0.00000000000000 ]
! - [ -0.11674136018427, 0.04305724458615 ]
readvec = .false.
do while (getline_raw(lu,line,.false.))
if (index(line,"q-position") > 0) then
! a new q-point, increase nqpt and reallocate
Expand Down Expand Up @@ -639,6 +642,7 @@ subroutine read_phonopy_yaml(c,vib,file,errmsg,ti)
read (line,*,err=999,end=999) vib%freq(ifreq,vib%nqpt)

elseif (index(line,"eigenvector") > 0) then
readvec = .true.
! an eigenvector
do i = 1, c%ncel
ok = getline_raw(lu,line,.false.)
Expand All @@ -658,14 +662,22 @@ subroutine read_phonopy_yaml(c,vib,file,errmsg,ti)
call realloc(vib%qpt,3,vib%nqpt)
call realloc(vib%freq,vib%nfreq,vib%nqpt)
call realloc(vib%vec,3,c%ncel,vib%nfreq,vib%nqpt)
if (.not.readvec) then
errmsg = "the yaml file contains no eigenvector information"
goto 999
end if

! THz to cm-1
vib%freq = vib%freq / cm1tothz

! normalize
do i = 1, vib%nfreq
vib%vec(:,:,i,1) = vib%vec(:,:,i,1) / &
sqrt(sum(vib%vec(:,:,i,1)*conjg(vib%vec(:,:,i,1))))
norm = sqrt(sum(vib%vec(:,:,i,1)*conjg(vib%vec(:,:,i,1))))
if (norm < eps_error) then
errmsg = "zero-length eigenvector found (the yaml file has eigenvector?)"
goto 999
end if
vib%vec(:,:,i,1) = vib%vec(:,:,i,1) / norm
end do

! ! checking normalization
Expand Down
10 changes: 5 additions & 5 deletions src/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ module subroutine critic_main()
if (.not.ok) cycle
call struct_newcell(sy,subline,.not.quiet)

! ! vibrations
! elseif (equal(word,'vibrations')) then
! call check_structure_defined(ok)
! if (.not.ok) cycle
! call struct_vibrations(sy,subline,.not.quiet)
! vibrations
elseif (equal(word,'vibrations')) then
call check_structure_defined(ok)
if (.not.ok) cycle
call struct_vibrations(sy,subline,.not.quiet)

! molcell
elseif (equal(word,'molcell')) then
Expand Down

0 comments on commit dc7bb4b

Please sign in to comment.