Octopus
symmetries.F90
Go to the documentation of this file.
1!! Copyright (C) 2009 X. Andrade
2!!
3!! This program is free software; you can redistribute it and/or modify
4!! it under the terms of the GNU General Public License as published by
5!! the Free Software Foundation; either version 2, or (at your option)
6!! any later version.
7!!
8!! This program is distributed in the hope that it will be useful,
9!! but WITHOUT ANY WARRANTY; without even the implied warranty of
10!! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11!! GNU General Public License for more details.
12!!
13!! You should have received a copy of the GNU General Public License
14!! along with this program; if not, write to the Free Software
15!! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16!! 02110-1301, USA.
17!!
18
19#include "global.h"
20
22 use debug_oct_m
23 use global_oct_m
24 use iso_c_binding
25 use, intrinsic :: iso_fortran_env
27 use math_oct_m
29 use mpi_oct_m
31 use parser_oct_m
33 use string_oct_m
34 use space_oct_m
35 use spglib_f08
37
38 implicit none
39
40 private
41
42 public :: &
53
54 type symmetries_t
55 private
56 type(symm_op_t), allocatable, public :: ops(:)
57 integer, public :: nops = 0
58 real(real64) :: breakdir(1:3)
59 integer, public :: periodic_dim
60 integer :: space_group
61 logical :: any_non_spherical
62 logical :: symmetries_compute = .false.
63 character(len=6) :: group_name = ""
64 character(len=30) :: group_elements = ""
65 character(len=11) :: symbol = ""
66 character(len=7) :: schoenflies = ""
67
68 type(symm_op_t), allocatable, public :: non_symmorphic_ops(:)
69 integer, public :: nops_nonsymmorphic = 0
70 logical :: use_nonsymmorphic = .true.
71
74 integer, allocatable, public :: point_group(:, :, :)
75 contains
76 procedure :: copy => symmetries_copy
77 generic :: assignment(=) => copy
79 end type symmetries_t
80
81 real(real64), parameter, public :: default_symprec = 1.e-5_real64
82 real(real64), public :: symprec
83
85 interface
86 subroutine symmetries_finite_init(natoms, types, positions, verbosity, point_group)
87 use, intrinsic :: iso_fortran_env
88 integer, intent(in) :: natoms
89 integer, intent(in) :: types
90 real(real64), intent(in) :: positions
91 integer, intent(in) :: verbosity
92 integer, intent(out) :: point_group
94
95 subroutine symmetries_finite_get_group_name(point_group, name) bind(c)
96 use iso_c_binding
97 integer, intent(in) :: point_group
98 character(kind=c_char), intent(out) :: name(*)
100
101 subroutine symmetries_finite_get_group_elements(point_group, elements) bind(c)
102 use iso_c_binding
103 integer, intent(in) :: point_group
104 character(kind=c_char), intent(out) :: elements(*)
106
107 subroutine symmetries_finite_end()
108 end subroutine symmetries_finite_end
109 end interface
110
111 interface symmetries_t
112 module procedure symmetries_constructor
113 end interface symmetries_t
114
115contains
116
117 function symmetries_constructor(namespace, space, latt, n_sites, site_pos, site_type, spherical_site) result(this)
118 type(namespace_t), intent(in) :: namespace
119 class(space_t), intent(in) :: space
120 type(lattice_vectors_t), intent(in) :: latt
121 integer, intent(in) :: n_sites
122 real(real64), contiguous, intent(in) :: site_pos(:,:)
123 integer, intent(in) :: site_type(1:n_sites)
124 logical, contiguous, intent(in) :: spherical_site(:)
125 type(symmetries_t) :: this
127 integer :: dim4syms
128 integer :: idir, isite, isite_symm, iop, verbosity, point_group, irot, nrot
129 real(real64), allocatable :: position(:, :)
130 type(block_t) :: blk
131 type(symm_op_t) :: tmpop
132 integer :: identity(3,3)
133 integer, allocatable :: rotations(:, :, :)
134 logical :: found_identity, is_supercell
135 logical :: def_sym_comp
136 real(real64) :: rsite(space%dim)
137 character(kind=c_char) :: c_str(64)
139 type(spglibdataset) :: spg_dataset
140 type(spglibspacegrouptype) :: spg_spacegroup
143
144 ! if someone cares, they could try to analyze the symmetry point group of the individual species too
145 this%any_non_spherical = any(.not. spherical_site)
147 this%periodic_dim = space%periodic_dim
149 dim4syms = min(3, space%dim)
151 def_sym_comp = (n_sites < 100) .or. space%is_periodic()
152 def_sym_comp = def_sym_comp .and. space%dim == 3
154 !%Variable SymmetriesCompute
155 !%Type logical
156 !%Section Execution::Symmetries
157 !%Description
158 !% If disabled, <tt>Octopus</tt> will not compute
159 !% nor print the symmetries.
160 !%
161 !% By default, symmetries are computed when running in 3
162 !% dimensions for systems with less than 100 atoms.
163 !% For periodic systems, the default is always true, irrespective of the number of atoms.
164 !%End
165 call parse_variable(namespace, 'SymmetriesCompute', def_sym_comp, this%symmetries_compute)
166
167 !%Variable SymmetriesTolerance
168 !%Type float
169 !%Section Execution::Symmetries
170 !%Description
171 !% For periodic systems, this variable controls the tolerance used by the symmetry finder
172 !% (spglib) to find the spacegroup and symmetries of the crystal.
173 !%End
174 call parse_variable(namespace, 'SymmetriesTolerance', default_symprec, symprec)
175
176
177 if (this%symmetries_compute .and. space%dim /= 3) then
178 call messages_experimental('symmetries for non 3D systems', namespace=namespace)
179 end if
180
181 if (this%any_non_spherical .or. .not. this%symmetries_compute) then
182 call init_identity()
184 return
185 end if
186
187 ! In all cases, we must check that the grid respects the symmetries. --DAS
188
189 if (space%periodic_dim == 0) then
190
191 call init_identity()
192
193 ! for the moment symmetries are only used for information, so we compute them only on one node.
194 if (mpi_world%is_root()) then
195 verbosity = -1
196
197 safe_allocate(position(1:3, 1:n_sites))
198
199 do isite = 1, n_sites
200 position(1:3, isite) = m_zero
201 position(1:dim4syms, isite) = site_pos(1:dim4syms, isite)
202 end do
203
204 if (this%symmetries_compute) then
205 call symmetries_finite_init(n_sites, site_type(1), position(1, 1), verbosity, point_group)
206 if (point_group > -1) then
207 c_str = c_null_char
208 call symmetries_finite_get_group_name(point_group, c_str)
209 call string_c_to_f(c_str, this%group_name)
210
211 c_str = c_null_char
212 call symmetries_finite_get_group_elements(point_group, c_str)
213 call string_c_to_f(c_str, this%group_elements)
214 else
215 this%group_name = ""
216 this%group_elements = ""
217 this%symbol = ""
218 this%schoenflies = ""
219 this%symmetries_compute = .false.
220 end if
222 end if
223 safe_deallocate_a(position)
224 end if
225
226 else
227
228 !%Variable SymmetriesUseNonSymmorphic
229 !%Type logical
230 !%Default yes
231 !%Section Execution::Symmetries
232 !%Description
233 !% For periodic systems, this variable controls if the code tries to use available
234 !% non-symmorphic symmetries.
235 !%End
236 call parse_variable(namespace, 'SymmetriesUseNonSymmorphic', .true., this%use_nonsymmorphic)
237
238
239 spg_dataset = symmetries_get_spg_dataset(namespace, space, latt, n_sites, site_pos, site_type)
240 if (spg_dataset%spglib_error /= 0) then
241 call init_identity()
243 return
244 end if
245
246 this%space_group = spg_dataset%spacegroup_number
247 this%symbol = spg_dataset%international_symbol
248 spg_spacegroup = spg_get_spacegroup_type(spg_dataset%hall_number)
249 this%schoenflies = spg_spacegroup%schoenflies
250
251 do iop = 1, spg_dataset%n_operations
252 ! transpose due to array order difference between C and fortran
253 spg_dataset%rotations(:,:,iop) = transpose(spg_dataset%rotations(:,:,iop))
254 ! sometimes spglib may return lattice vectors as 'fractional' translations
255 spg_dataset%translations(:, iop) = spg_dataset%translations(:, iop) - &
256 anint(spg_dataset%translations(:, iop) + m_half * tol_translation)
257 end do
258
259 ! we need to check that it is not a supercell, as in the QE routine (sgam_at)
260 ! they disable fractional translations if the identity has one, because the sym ops might not form a group.
261 ! spglib may return duplicate operations in this case!
262 is_supercell = (spg_dataset%n_operations > 48)
263 found_identity = .false.
264 identity = diagonal_matrix(3, 1)
265 do iop = 1, spg_dataset%n_operations
266 if (all(spg_dataset%rotations(1:3, 1:3, iop) == identity(1:3, 1:3))) then
267 found_identity = .true.
268 if (any(abs(spg_dataset%translations(1:3, iop)) > tol_translation )) then
269 is_supercell = .true.
270 write(message(1),'(a,3f12.6)') 'Identity has a fractional translation ', spg_dataset%translations(1:3, iop)
271 call messages_info(1, namespace=namespace)
272 end if
273 end if
274 end do
275 if (.not. found_identity) then
276 message(1) = "Symmetries internal error: Identity is missing from symmetry operations."
277 call messages_fatal(1, namespace=namespace)
278 end if
279
280 if (is_supercell) then
281 message(1) = "Disabling fractional translations. System appears to be a supercell."
282 call messages_info(1, namespace=namespace)
283 end if
284 ! actually, we do not use fractional translations regardless currently
285
286 ! Distinct rotations of all the operations
287 safe_allocate(rotations(1:3, 1:3, 1:spg_dataset%n_operations))
288 nrot = 0
289 do iop = 1, spg_dataset%n_operations
290 if (any([(all(rotations(:, :, irot) == spg_dataset%rotations(:, :, iop)), irot = 1, nrot)])) cycle
291 nrot = nrot + 1
292 rotations(:, :, nrot) = spg_dataset%rotations(:, :, iop)
293 end do
294 safe_allocate_source(this%point_group(1:3, 1:3, 1:nrot), rotations(:, :, 1:nrot))
295 safe_deallocate_a(rotations)
296
297 ! this is a hack to get things working, this variable should be
298 ! eliminated and the direction calculated automatically from the
299 ! perturbations.
300
301 !%Variable SymmetryBreakDir
302 !%Type block
303 !%Section Mesh::Simulation Box
304 !%Description
305 !% This variable specifies a direction in which the symmetry of
306 !% the system will be broken. This is useful for generating <i>k</i>-point
307 !% grids when an external perturbation is applied.
308 !%End
309
310 this%breakdir(1:3) = m_zero
311
312 if (parse_block(namespace, 'SymmetryBreakDir', blk) == 0) then
313
314 do idir = 1, dim4syms
315 call parse_block_float(blk, 0, idir - 1, this%breakdir(idir))
316 end do
317
318 call parse_block_end(blk)
319
320 end if
321
322 safe_allocate(this%ops(1:spg_dataset%n_operations))
323 safe_allocate(this%non_symmorphic_ops(1:spg_dataset%n_operations))
324
325 ! check all operations and leave those that kept the symmetry-breaking
326 ! direction invariant and (for the moment) that do not have a translation
327 this%nops = 0
328 ! We also keep track of all non-symmorphic operations
329 this%nops_nonsymmorphic = 0
330 do iop = 1, spg_dataset%n_operations
331 ! If spglib returns tiny translations, we set them to zero to avoid numerical artifacts
332 if (all(abs(spg_dataset%translations(1:3, iop)) < tol_translation)) then
333 spg_dataset%translations(1:3, iop) = m_zero
334 end if
335
336 ! Reject all symmetries involving fractional translation in the non-periodic dimension
337 if (any(abs(spg_dataset%translations(space%periodic_dim+1:3, iop)) > tol_translation)) cycle
338
339 call symm_op_init(tmpop, spg_dataset%rotations(1:3, 1:3, iop), latt, dim4syms, spg_dataset%translations(1:3, iop))
340
341 ! If we do not specify SymmetryBreakDir, we want to use all symmetries
342 if( all(abs(this%breakdir) < m_epsilon) ) then
343 if (.not. symm_op_has_translation(tmpop, tol_translation)) then
344 this%nops = this%nops + 1
345 call symm_op_copy(tmpop, this%ops(this%nops))
346 else if(.not. is_supercell .and. this%use_nonsymmorphic) then
347 this%nops_nonsymmorphic = this%nops_nonsymmorphic + 1
348 call symm_op_copy(tmpop, this%non_symmorphic_ops(this%nops_nonsymmorphic))
349 end if
350 else if (symm_op_invariant_cart(tmpop, this%breakdir, symprec)) then
351 if(.not. symm_op_has_translation(tmpop, symprec)) then
352 this%nops = this%nops + 1
353 call symm_op_copy(tmpop, this%ops(this%nops))
354 else if(.not. is_supercell .and. this%use_nonsymmorphic) then
355 this%nops_nonsymmorphic = this%nops_nonsymmorphic + 1
356 call symm_op_copy(tmpop, this%non_symmorphic_ops(this%nops_nonsymmorphic))
357 end if
358 end if
359 end do
360
361
362 end if
363
364 call symmetries_write_info(this, space, namespace=namespace)
365
366 ! Checks if that the atomic coordinates are compatible with the symmetries
367 !
368 ! We want to use for instance that
369 !
370 ! \int dr f(Rr) V_isite(r) \nabla f(R(v)) = R\int dr f(r) V_isite(R*r) f(r)
371 !
372 ! and that the operator R should map the position of atom
373 ! isite to the position of some other atom isite_symm, so that
374 !
375 ! V_isite(R*r) = V_isite_symm(r)
376 !
377 do iop = 1, symmetries_number(this)
378 if (iop == symmetries_identity_index(this)) cycle
379
380 do isite = 1, n_sites
381 rsite = symm_op_apply_cart(this%ops(iop), site_pos(:, isite))
382
383 rsite = latt%fold_into_cell(rsite)
384
385 ! find isite_symm
386 do isite_symm = 1, n_sites
387 if (all(abs(rsite - site_pos(:, isite_symm)) < symprec)) exit
388 end do
389
390 if (isite_symm > n_sites) then
391 write(message(1),'(a,i6)') 'Internal error: could not find symmetric partner for atom number', isite
392 write(message(2),'(a,i3,a)') 'with symmetry operation number ', iop, '.'
393 call messages_fatal(2, namespace=namespace)
394 end if
395
396 end do
397 end do
398
399 ! Check non-symmorphic operations
400 do iop = 1, this%nops_nonsymmorphic
401 do isite = 1, n_sites
402 rsite = symm_op_apply_cart(this%non_symmorphic_ops(iop), site_pos(:, isite))
403
404 rsite = latt%fold_into_cell(rsite)
405
406 ! find isite_symm
407 do isite_symm = 1, n_sites
408 if (all(abs(rsite - site_pos(:, isite_symm)) < symprec)) exit
409 end do
410
411 if (isite_symm > n_sites) then
412 write(message(1),'(a,i6)') 'Internal error: could not find symmetric partner for atom number', isite
413 write(message(2),'(a,i3,a)') 'with non-symmorphic symmetry operation number ', iop, '.'
414 call messages_fatal(2, namespace=namespace)
415 end if
416
417 end do
418 end do
419
421
422 contains
423
424 subroutine init_identity()
425
426 push_sub(symmetries_init.init_identity)
427
428 safe_allocate(this%ops(1))
429 this%nops = 1
430 call symm_op_init(this%ops(1), diagonal_matrix(3, 1), latt, dim4syms)
431 safe_allocate(this%point_group(1:3, 1:3, 1:1))
432 this%point_group(:, :, 1) = diagonal_matrix(3, 1)
433 this%nops_nonsymmorphic = 0
434 this%breakdir = m_zero
435 this%space_group = 1
436
437 pop_sub(symmetries_init.init_identity)
438
439 end subroutine init_identity
440
441 end function symmetries_constructor
442
443 ! -------------------------------------------------------------------------------
444 subroutine symmetries_copy(lhs, rhs)
445 class(symmetries_t), intent(out) :: lhs
446 class(symmetries_t), intent(in) :: rhs
447
448 integer :: iop
449
450 push_sub(symmetries_copy)
451
452 safe_allocate(lhs%ops(1:ubound(rhs%ops, dim=1)))
453 do iop = 1, rhs%nops
454 call symm_op_copy(rhs%ops(iop), lhs%ops(iop))
455 end do
456 lhs%nops = rhs%nops
457 safe_allocate(lhs%non_symmorphic_ops(1:rhs%nops_nonsymmorphic))
458 do iop = 1, rhs%nops_nonsymmorphic
459 call symm_op_copy(rhs%non_symmorphic_ops(iop), lhs%non_symmorphic_ops(iop))
460 end do
461 lhs%nops_nonsymmorphic = rhs%nops_nonsymmorphic
462 lhs%breakdir = rhs%breakdir
463 lhs%periodic_dim = rhs%periodic_dim
464 lhs%space_group = rhs%space_group
465 lhs%any_non_spherical = rhs%any_non_spherical
466 lhs%symmetries_compute = rhs%symmetries_compute
467 lhs%group_name = rhs%group_name
468 lhs%group_elements = rhs%group_elements
469 lhs%symbol = rhs%symbol
470 lhs%schoenflies = rhs%schoenflies
471 lhs%use_nonsymmorphic = rhs%use_nonsymmorphic
472 if (allocated(rhs%point_group)) then
473 safe_allocate_source_a(lhs%point_group, rhs%point_group)
474 end if
475
476 pop_sub(symmetries_copy)
477 end subroutine symmetries_copy
478
479 ! -------------------------------------------------------------------------------
480
481 subroutine symmetries_finalizer(this)
482 type(symmetries_t), intent(inout) :: this
483
484 push_sub(symmetries_finalizer)
485
486 safe_deallocate_a(this%ops)
487 safe_deallocate_a(this%non_symmorphic_ops)
488 safe_deallocate_a(this%point_group)
489
490 pop_sub(symmetries_finalizer)
491 end subroutine symmetries_finalizer
492
493 ! -------------------------------------------------------------------------------
494
495 integer pure function symmetries_number(this) result(number)
496 type(symmetries_t), intent(in) :: this
497
498 number = this%nops
499 end function symmetries_number
500
501 ! -------------------------------------------------------------------------------
502
503 subroutine symmetries_apply_kpoint_red(this, iop, aa, bb)
504 type(symmetries_t), intent(in) :: this
505 integer, intent(in) :: iop
506 real(real64), intent(in) :: aa(1:3)
507 real(real64), intent(out) :: bb(1:3)
508
510
511 assert(iop /= 0 .and. abs(iop) <= this%nops)
512
513 !Time-reversal symmetry
514 if (iop < 0) then
515 bb(1:3) = symm_op_apply_transpose_red(this%ops(abs(iop)), -aa(1:3))
516 else
517 bb(1:3) = symm_op_apply_transpose_red(this%ops(abs(iop)), aa(1:3))
518 end if
519
521 end subroutine symmetries_apply_kpoint_red
522
523 ! -------------------------------------------------------------------------------
524
525 integer pure function symmetries_space_group_number(this) result(number)
526 type(symmetries_t), intent(in) :: this
527
528 number = this%space_group
530
531 ! -------------------------------------------------------------------------------
532
533 logical pure function symmetries_have_break_dir(this) result(have)
534 type(symmetries_t), intent(in) :: this
535
536 have = any(abs(this%breakdir(1:3)) > m_epsilon)
537 end function symmetries_have_break_dir
538
539 ! -------------------------------------------------------------------------------
540
541 integer pure function symmetries_identity_index(this) result(index)
542 type(symmetries_t), intent(in) :: this
543
544 integer :: iop
545
546 index = -1
547 do iop = 1, this%nops
548 if (symm_op_is_identity(this%ops(iop))) then
549 index = iop
550 cycle
551 end if
552 end do
554 end function symmetries_identity_index
555
556 ! ---------------------------------------------------------
557 subroutine symmetries_write_info(this, space, iunit, namespace)
558 type(symmetries_t), intent(in) :: this
559 class(space_t), intent(in) :: space
560 integer, optional, intent(in) :: iunit
561 type(namespace_t), optional, intent(in) :: namespace
562
563 integer :: iop
564
565 push_sub(symmetries_write_info)
566
567 call messages_print_with_emphasis(msg='Symmetries', iunit=iunit, namespace=namespace)
568
569 if (this%any_non_spherical) then
570 message(1) = "Symmetries are disabled since non-spherically symmetric species may be present."
571 call messages_info(1,iunit = iunit, namespace=namespace)
572 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
573 pop_sub(symmetries_write_info)
574 return
575 end if
576
577 if (.not. this%symmetries_compute) then
578 message(1) = "Symmetries have been disabled by SymmetriesCompute = false."
579 call messages_info(1, iunit=iunit, namespace=namespace)
580 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
581 pop_sub(symmetries_write_info)
582 return
583 end if
584
585 if (space%periodic_dim == 0) then
586 ! At the moment only the root node has information about symmetries of finite systems.
587 if (mpi_world%is_root()) then
588 if (this%symmetries_compute) then
589 call messages_write('Symmetry elements : '//trim(this%group_elements), new_line = .true.)
590 call messages_write('Symmetry group : '//trim(this%group_name))
591 call messages_info(iunit=iunit, namespace=namespace)
592 end if
593 end if
594 else
595 write(message(1),'(a, i4)') 'Space group No. ', this%space_group
596 write(message(2),'(2a)') 'International: ', trim(this%symbol)
597 write(message(3),'(2a)') 'Schoenflies: ', trim(this%schoenflies)
598 call messages_info(3, iunit=iunit, namespace=namespace)
599
600 write(message(1), '(a,i5,a)') 'Info: The system has ', this%nops, ' symmetries that can be used.'
601 call messages_info(1, iunit=iunit, namespace=namespace)
602
603 write(message(1),'(a7,a31,12x,a33)') 'Index', 'Rotation matrix', 'Fractional translations'
604 call messages_info(1, iunit=iunit, namespace=namespace)
605 do iop = 1, this%nops
606 ! list all operations and leave those that kept the symmetry-breaking
607 ! direction invariant and (for the moment) that do not have a translation
608 if (space%dim == 1) then
609 write(message(1),'(i5,1x,a,2x,1(1i4,2x),1f12.6)') iop, ':', symm_op_rotation_matrix_red(this%ops(iop)), &
610 symm_op_translation_vector_red(this%ops(iop))
611 end if
612 if (space%dim == 2) then
613 write(message(1),'(i5,1x,a,2x,2(2i4,2x),2f12.6)') iop, ':', symm_op_rotation_matrix_red(this%ops(iop)), &
614 symm_op_translation_vector_red(this%ops(iop))
615 end if
616 if (space%dim == 3) then
617 write(message(1),'(i5,1x,a,2x,3(3i4,2x),3f12.6)') iop, ':', symm_op_rotation_matrix_red(this%ops(iop)), &
618 symm_op_translation_vector_red(this%ops(iop))
619 end if
620 call messages_info(1, iunit=iunit, namespace=namespace)
621 end do
622
623 write(message(1), '(a,i5,a)') 'Info: The system also has ', this%nops_nonsymmorphic, &
624 ' nonsymmorphic symmetries that are not used for electrons.'
625 call messages_info(1, iunit=iunit, namespace=namespace)
626 do iop = 1, this%nops_nonsymmorphic
627 ! list all operations and leave those that kept the symmetry-breaking
628 ! direction invariant and (for the moment) that do not have a translation
629 if (space%dim == 1) then
630 write(message(1),'(i5,1x,a,2x,1(1i4,2x),1f12.6)') iop, ':', symm_op_rotation_matrix_red(this%non_symmorphic_ops(iop)), &
631 symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
632 end if
633 if (space%dim == 2) then
634 write(message(1),'(i5,1x,a,2x,2(2i4,2x),2f12.6)') iop, ':', symm_op_rotation_matrix_red(this%non_symmorphic_ops(iop)), &
635 symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
636 end if
637 if (space%dim == 3) then
638 write(message(1),'(i5,1x,a,2x,3(3i4,2x),3f12.6)') iop, ':', symm_op_rotation_matrix_red(this%non_symmorphic_ops(iop)), &
639 symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
640 end if
641 call messages_info(1, iunit=iunit, namespace=namespace)
642 end do
643 end if
644 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
645
646 pop_sub(symmetries_write_info)
647 end subroutine symmetries_write_info
648
649 ! ---------------------------------------------------------
651 subroutine symmetries_update_lattice_vectors(this, latt, dim)
652 type(symmetries_t), intent(inout) :: this
653 type(lattice_vectors_t), intent(in) :: latt
654 integer, intent(in) :: dim
655
656 integer :: iop
657
659
660 do iop = 1, this%nops
661 call symm_op_build_cartesian(this%ops(iop), latt, dim)
662 end do
663 do iop = 1, this%nops_nonsymmorphic
664 call symm_op_build_cartesian(this%non_symmorphic_ops(iop), latt, dim)
665 end do
666
668 end subroutine
669
671 type(spglibdataset) function symmetries_get_spg_dataset(namespace, space, latt, n_sites, site_pos, site_type) result(spg_dataset)
672 type(namespace_t), intent(in) :: namespace
673 class(space_t), intent(in) :: space
674 type(lattice_vectors_t), intent(in) :: latt
675 integer, intent(in) :: n_sites
676 real(real64), contiguous, intent(in) :: site_pos(:,:)
677 integer, intent(in) :: site_type(1:n_sites)
678
679 integer :: isite, idir, dim4syms
680 real(real64), allocatable :: position(:, :)
681 real(real64) :: lattice(1:3, 1:3)
682
684
685 assert(space%is_periodic())
686
687 dim4syms = min(3, space%dim)
688
689 safe_allocate(position(1:3, 1:n_sites))
690
691 do isite = 1, n_sites
692 position(1:3,isite) = m_zero
693
694 ! Transform atomic positions to reduced coordinates
695 position(1:dim4syms, isite) = latt%cart_to_red(site_pos(1:dim4syms, isite))
696 position(1:dim4syms, isite) = position(1:dim4syms, isite) - m_half
697 do idir = 1, dim4syms
698 position(idir, isite) = position(idir, isite) - anint(position(idir, isite))
699 end do
700 position(1:dim4syms, isite) = position(1:dim4syms,isite) + m_half
701 end do
702
703 lattice = m_zero
704 !NOTE: Why "inverse matrix" ? (NTD)
705 ! get inverse matrix to extract reduced coordinates for spglib
706 lattice(1:space%periodic_dim, 1:space%periodic_dim) = latt%rlattice(1:space%periodic_dim, 1:space%periodic_dim)
707 ! transpose the lattice vectors for use in spglib as row-major matrix
708 lattice(:,:) = transpose(lattice(:,:))
709 ! spglib always assume 3D periodicity, so we need to set the lattice vectors along the non-periodic dimensions.
710 ! Here we choose a value that should guarantee that no incorrect symmetries are found along the non-periodic dimensions.
711 do idir = space%periodic_dim + 1, 3
712 if (idir <= space%dim) then
713 lattice(idir, idir) = m_two*(maxval(site_pos(idir, :)) - minval(site_pos(idir, :))) + m_one
714 else
715 lattice(idir, idir) = m_one
716 end if
717 end do
718
719 spg_dataset = spg_get_dataset(lattice, position, site_type, n_sites, symprec)
720 if (spg_dataset%spglib_error /= 0) then
721 message(1) = "Symmetry analysis failed in spglib. Disabling symmetries."
722 call messages_warning(1, namespace=namespace)
724 do isite = 1, n_sites
725 write(message(1),'(a,i6,a,3f12.6,a,3f12.6)') 'type ', site_type(isite), &
726 ' reduced coords ', position(:, isite), ' cartesian coords ', site_pos(:, isite)
727 call messages_info(1, namespace=namespace)
728 end do
729 end if
730 safe_deallocate_a(position)
731
733 end function symmetries_get_spg_dataset
734
737 subroutine symmetries_use_compatible_nonsymmorphic(this, ll, namespace)
738 type(symmetries_t), intent(inout) :: this
739 integer, intent(in) :: ll(3)
740 type(namespace_t), intent(in) :: namespace
741
742 integer :: iop, iop2, ncompatible, nops_nonsymmorphic
743 real(real64) :: trans(3)
744
746
747
748 ncompatible = 0
749 nops_nonsymmorphic = this%nops_nonsymmorphic
750 iop = 1
751 do while (iop <= nops_nonsymmorphic)
752 trans = symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
753
754 if (all(abs(trans * ll - anint(trans * ll)) < symprec) ) then
755 ncompatible = ncompatible + 1
756 call symm_op_copy(this%non_symmorphic_ops(iop), this%ops(this%nops + ncompatible))
757 do iop2 = iop + 1, nops_nonsymmorphic
758 call symm_op_copy(this%non_symmorphic_ops(iop2), this%non_symmorphic_ops(iop2-1))
759 end do
760 nops_nonsymmorphic = nops_nonsymmorphic - 1
761 else
762 iop = iop + 1
763 end if
764 end do
765
766 if (ncompatible == 0) then
768 return
769 end if
770
771 call messages_print_with_emphasis(msg='Symmetries refinement', namespace=namespace)
772
773 write(message(1), '(a,i5,a)') 'Info: The system has ', ncompatible, &
774 ' non-symmorphic symmetries that are compatible with the grid.'
775 call messages_info(1, namespace=namespace)
776
777 write(message(1),'(a7,a31,12x,a33)') 'Index', 'Rotation matrix', 'Fractional translations'
778 call messages_info(1, namespace=namespace)
779 do iop = this%nops+1, this%nops+ncompatible
780 write(message(1),'(i5,1x,a,2x,3(3i4,2x),3f12.6)') iop, ':', symm_op_rotation_matrix_red(this%ops(iop)), &
781 symm_op_translation_vector_red(this%ops(iop))
782 call messages_info(1, namespace=namespace)
783 end do
784
785 this%nops_nonsymmorphic = nops_nonsymmorphic
786 this%nops = this%nops + ncompatible
787
788 call messages_print_with_emphasis(namespace=namespace)
789
792
793end module symmetries_oct_m
794
795!! Local Variables:
796!! mode: f90
797!! coding: utf-8
798!! End:
NOTE: unfortunately, these routines use global variables shared among them.
Definition: symmetries.F90:158
real(real64), parameter, public m_zero
Definition: global.F90:173
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_half
Definition: global.F90:179
This module is intended to contain "only mathematical" functions and procedures.
Definition: math.F90:94
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:138
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:386
subroutine, public messages_experimental(name, namespace)
Definition: messages.F90:1020
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
Definition: messages.F90:570
type(mpi_grp_t), public mpi_world
Definition: mpi.F90:317
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:600
/* To use the profiling module, call profiling_in and profiling_out with the label of the region as a...
Definition: profiling.F90:122
subroutine, public string_c_to_f(c_string, f_string)
convert a C string to a Fortran string
Definition: string.F90:253
subroutine, public symm_op_copy(inp, outp)
Definition: symm_op.F90:255
logical pure function, public symm_op_has_translation(this, prec)
Definition: symm_op.F90:272
real(real64), parameter, public tol_translation
Definition: symm_op.F90:162
subroutine, public symm_op_init(this, rot, latt, dim, trans)
Definition: symm_op.F90:169
subroutine, public symmetries_update_lattice_vectors(this, latt, dim)
Updates the symmetry operations when lattice vectors are updated.
Definition: symmetries.F90:724
subroutine, public symmetries_apply_kpoint_red(this, iop, aa, bb)
Definition: symmetries.F90:576
integer pure function, public symmetries_space_group_number(this)
Definition: symmetries.F90:598
integer pure function, public symmetries_identity_index(this)
Definition: symmetries.F90:614
type(symmetries_t) function symmetries_constructor(namespace, space, latt, n_sites, site_pos, site_type, spherical_site)
Definition: symmetries.F90:190
subroutine, public symmetries_write_info(this, space, iunit, namespace)
Definition: symmetries.F90:630
real(real64), public symprec
Definition: symmetries.F90:154
integer pure function, public symmetries_number(this)
Definition: symmetries.F90:568
subroutine symmetries_copy(lhs, rhs)
Definition: symmetries.F90:517
logical pure function, public symmetries_have_break_dir(this)
Definition: symmetries.F90:606
type(spglibdataset) function, public symmetries_get_spg_dataset(namespace, space, latt, n_sites, site_pos, site_type)
Returns the SpglibDataset for the system.
Definition: symmetries.F90:744
subroutine symmetries_finalizer(this)
Definition: symmetries.F90:554
subroutine, public symmetries_use_compatible_nonsymmorphic(this, ll, namespace)
Detect if some non-symmorphic operations are compatible with the real-space grid If yes,...
Definition: symmetries.F90:810
subroutine init_identity()
Definition: symmetries.F90:497
int true(void)