25 use,
intrinsic :: iso_fortran_env
55 type(symm_op_t),
allocatable,
public :: ops(:)
56 integer,
public :: nops = 0
57 real(real64) :: breakdir(1:3)
58 integer,
public :: periodic_dim
59 integer :: space_group
60 logical :: any_non_spherical
61 logical :: symmetries_compute = .false.
62 character(len=6) :: group_name =
""
63 character(len=30) :: group_elements =
""
64 character(len=11) :: symbol =
""
65 character(len=7) :: schoenflies =
""
67 type(symm_op_t),
allocatable,
public :: non_symmorphic_ops(:)
68 integer,
public :: nops_nonsymmorphic = 0
71 generic ::
assignment(=) => copy
75 real(real64),
parameter,
public :: default_symprec = 1.e-5_real64
76 real(real64),
public :: symprec
81 use,
intrinsic :: iso_fortran_env
82 integer,
intent(in) :: natoms
83 integer,
intent(in) :: types
84 real(real64),
intent(in) :: positions
85 integer,
intent(in) :: verbosity
86 integer,
intent(out) :: point_group
90 integer,
intent(in) :: point_group
91 character(len=*),
intent(out) :: name
95 integer,
intent(in) :: point_group
96 character(len=*),
intent(out) :: elements
109 function symmetries_constructor(namespace, space, latt, n_sites, site_pos, site_type, spherical_site)
result(this)
110 type(namespace_t),
intent(in) :: namespace
111 class(space_t),
intent(in) :: space
112 type(lattice_vectors_t),
intent(in) :: latt
113 integer,
intent(in) :: n_sites
114 real(real64),
intent(in) :: site_pos(:,:)
115 integer,
intent(in) :: site_type(1:n_sites)
116 logical,
intent(in) :: spherical_site(:)
117 type(symmetries_t) :: this
120 integer :: idir, isite, isite_symm, iop, verbosity, point_group
121 real(real64),
allocatable :: position(:, :)
123 type(symm_op_t) :: tmpop
124 integer :: identity(3,3)
125 logical :: found_identity, is_supercell
126 logical :: def_sym_comp
127 real(real64) :: rsite(space%dim)
129 type(SpglibDataset) :: spg_dataset
130 type(SpglibSpacegroupType) :: spg_spacegroup
135 this%any_non_spherical = any(.not. spherical_site)
137 this%periodic_dim = space%periodic_dim
139 dim4syms = min(3, space%dim)
141 def_sym_comp = (n_sites < 100) .or. space%is_periodic()
142 def_sym_comp = def_sym_comp .and. space%dim == 3
155 call parse_variable(namespace,
'SymmetriesCompute', def_sym_comp, this%symmetries_compute)
167 if (this%symmetries_compute .and. space%dim /= 3)
then
171 if (this%any_non_spherical .or. .not. this%symmetries_compute)
then
179 if (space%periodic_dim == 0)
then
187 safe_allocate(position(1:3, 1:n_sites))
189 do isite = 1, n_sites
190 position(1:3, isite) =
m_zero
191 position(1:dim4syms, isite) = site_pos(1:dim4syms, isite)
194 if (this%symmetries_compute)
then
196 if (point_group > -1)
then
201 this%group_elements =
""
203 this%schoenflies =
""
204 this%symmetries_compute = .false.
208 safe_deallocate_a(position)
214 if (spg_dataset%spglib_error /= 0)
then
220 this%space_group = spg_dataset%spacegroup_number
221 this%symbol = spg_dataset%international_symbol
223 this%schoenflies = spg_spacegroup%schoenflies
225 do iop = 1, spg_dataset%n_operations
227 spg_dataset%rotations(:,:,iop) = transpose(spg_dataset%rotations(:,:,iop))
229 spg_dataset%translations(:, iop) = spg_dataset%translations(:, iop) - &
236 is_supercell = (spg_dataset%n_operations > 48)
237 found_identity = .false.
239 do iop = 1, spg_dataset%n_operations
240 if (all(spg_dataset%rotations(1:3, 1:3, iop) == identity(1:3, 1:3)))
then
241 found_identity = .
true.
242 if (any(abs(spg_dataset%translations(1:3, iop)) >
tol_translation ))
then
243 is_supercell = .
true.
244 write(
message(1),
'(a,3f12.6)')
'Identity has a fractional translation ', spg_dataset%translations(1:3, iop)
249 if (.not. found_identity)
then
250 message(1) =
"Symmetries internal error: Identity is missing from symmetry operations."
254 if (is_supercell)
then
255 message(1) =
"Disabling fractional translations. System appears to be a supercell."
273 this%breakdir(1:3) =
m_zero
275 if (
parse_block(namespace,
'SymmetryBreakDir', blk) == 0)
then
277 do idir = 1, dim4syms
285 safe_allocate(this%ops(1:spg_dataset%n_operations))
286 safe_allocate(this%non_symmorphic_ops(1:spg_dataset%n_operations))
292 this%nops_nonsymmorphic = 0
293 do iop = 1, spg_dataset%n_operations
295 if (all(abs(spg_dataset%translations(1:3, iop)) <
tol_translation))
then
296 spg_dataset%translations(1:3, iop) =
m_zero
300 if (any(abs(spg_dataset%translations(space%periodic_dim+1:3, iop)) >
tol_translation)) cycle
302 call symm_op_init(tmpop, spg_dataset%rotations(1:3, 1:3, iop), latt, dim4syms, spg_dataset%translations(1:3, iop))
305 if( all(abs(this%breakdir) <
m_epsilon) )
then
307 this%nops = this%nops + 1
309 else if(.not. is_supercell)
then
310 this%nops_nonsymmorphic = this%nops_nonsymmorphic + 1
311 call symm_op_copy(tmpop, this%non_symmorphic_ops(this%nops_nonsymmorphic))
316 this%nops = this%nops + 1
341 do isite = 1, n_sites
344 rsite = latt%fold_into_cell(rsite)
347 do isite_symm = 1, n_sites
348 if (all(abs(rsite - site_pos(:, isite_symm)) < symprec))
exit
351 if (isite_symm > n_sites)
then
352 write(
message(1),
'(a,i6)')
'Internal error: could not find symmetric partner for atom number', isite
353 write(
message(2),
'(a,i3,a)')
'with symmetry operation number ', iop,
'.'
361 do iop = 1, this%nops_nonsymmorphic
362 do isite = 1, n_sites
365 rsite = latt%fold_into_cell(rsite)
368 do isite_symm = 1, n_sites
369 if (all(abs(rsite - site_pos(:, isite_symm)) < symprec))
exit
372 if (isite_symm > n_sites)
then
373 write(
message(1),
'(a,i6)')
'Internal error: could not find symmetric partner for atom number', isite
374 write(
message(2),
'(a,i3,a)')
'with non-symmorphic symmetry operation number ', iop,
'.'
389 safe_allocate(this%ops(1))
392 this%nops_nonsymmorphic = 0
411 safe_allocate(lhs%ops(1:rhs%nops))
416 safe_allocate(lhs%non_symmorphic_ops(1:rhs%nops_nonsymmorphic))
417 do iop = 1, rhs%nops_nonsymmorphic
418 call symm_op_copy(rhs%non_symmorphic_ops(iop), lhs%non_symmorphic_ops(iop))
420 lhs%nops_nonsymmorphic = rhs%nops_nonsymmorphic
421 lhs%breakdir = rhs%breakdir
422 lhs%periodic_dim = rhs%periodic_dim
423 lhs%space_group = rhs%space_group
424 lhs%any_non_spherical = rhs%any_non_spherical
425 lhs%symmetries_compute = rhs%symmetries_compute
426 lhs%group_name = rhs%group_name
427 lhs%group_elements = rhs%group_elements
428 lhs%symbol = rhs%symbol
429 lhs%schoenflies = rhs%schoenflies
441 safe_deallocate_a(this%ops)
442 safe_deallocate_a(this%non_symmorphic_ops)
459 integer,
intent(in) :: iop
460 real(real64),
intent(in) :: aa(1:3)
461 real(real64),
intent(out) :: bb(1:3)
465 assert(iop /= 0 .and. abs(iop) <= this%nops)
469 bb(1:3) = symm_op_apply_transpose_red(this%ops(abs(iop)), -aa(1:3))
471 bb(1:3) = symm_op_apply_transpose_red(this%ops(abs(iop)), aa(1:3))
479 integer pure function symmetries_space_group_number(this) result(number)
482 number = this%space_group
487 logical pure function symmetries_have_break_dir(this) result(have)
490 have = any(abs(this%breakdir(1:3)) > m_epsilon)
495 integer pure function symmetries_identity_index(this) result(index)
500 do iop = 1, this%nops
501 if (symm_op_is_identity(this%ops(iop)))
then
512 class(space_t),
intent(in) :: space
513 integer,
optional,
intent(in) :: iunit
514 type(namespace_t),
optional,
intent(in) :: namespace
520 call messages_print_with_emphasis(msg=
'Symmetries', iunit=iunit, namespace=namespace)
522 if (this%any_non_spherical)
then
523 message(1) =
"Symmetries are disabled since non-spherically symmetric species may be present."
524 call messages_info(1,iunit = iunit, namespace=namespace)
525 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
530 if (.not. this%symmetries_compute)
then
531 message(1) =
"Symmetries have been disabled by SymmetriesCompute = false."
532 call messages_info(1, iunit=iunit, namespace=namespace)
533 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
538 if (space%periodic_dim == 0)
then
540 if (mpi_grp_is_root(mpi_world))
then
541 if (this%symmetries_compute)
then
542 call messages_write(
'Symmetry elements : '//trim(this%group_elements), new_line = .
true.)
543 call messages_write(
'Symmetry group : '//trim(this%group_name))
544 call messages_info(iunit=iunit, namespace=namespace)
548 write(message(1),
'(a, i4)')
'Space group No. ', this%space_group
549 write(message(2),
'(2a)')
'International: ', trim(this%symbol)
550 write(message(3),
'(2a)')
'Schoenflies: ', trim(this%schoenflies)
551 call messages_info(3, iunit=iunit, namespace=namespace)
553 write(message(1),
'(a,i5,a)')
'Info: The system has ', this%nops,
' symmorphic symmetries that can be used.'
554 call messages_info(1, iunit=iunit, namespace=namespace)
556 write(message(1),
'(a7,a31,12x,a33)')
'Index',
'Rotation matrix',
'Fractional translations'
557 call messages_info(1, iunit=iunit, namespace=namespace)
558 do iop = 1, this%nops
561 if (space%dim == 1)
then
562 write(message(1),
'(i5,1x,a,2x,1(1i4,2x),1f12.6)') iop,
':', symm_op_rotation_matrix_red(this%ops(iop)), &
563 symm_op_translation_vector_red(this%ops(iop))
565 if (space%dim == 2)
then
566 write(message(1),
'(i5,1x,a,2x,2(2i4,2x),2f12.6)') iop,
':', symm_op_rotation_matrix_red(this%ops(iop)), &
567 symm_op_translation_vector_red(this%ops(iop))
569 if (space%dim == 3)
then
570 write(message(1),
'(i5,1x,a,2x,3(3i4,2x),3f12.6)') iop,
':', symm_op_rotation_matrix_red(this%ops(iop)), &
571 symm_op_translation_vector_red(this%ops(iop))
573 call messages_info(1, iunit=iunit, namespace=namespace)
576 write(message(1),
'(a,i5,a)')
'Info: The system also has ', this%nops_nonsymmorphic, &
577 ' nonsymmorphic symmetries (not used for electrons).'
578 call messages_info(1, iunit=iunit, namespace=namespace)
579 do iop = 1, this%nops_nonsymmorphic
582 if (space%dim == 1)
then
583 write(message(1),
'(i5,1x,a,2x,1(1i4,2x),1f12.6)') iop,
':', symm_op_rotation_matrix_red(this%non_symmorphic_ops(iop)), &
584 symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
586 if (space%dim == 2)
then
587 write(message(1),
'(i5,1x,a,2x,2(2i4,2x),2f12.6)') iop,
':', symm_op_rotation_matrix_red(this%non_symmorphic_ops(iop)), &
588 symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
590 if (space%dim == 3)
then
591 write(message(1),
'(i5,1x,a,2x,3(3i4,2x),3f12.6)') iop,
':', symm_op_rotation_matrix_red(this%non_symmorphic_ops(iop)), &
592 symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
594 call messages_info(1, iunit=iunit, namespace=namespace)
597 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
606 type(lattice_vectors_t),
intent(in) :: latt
607 integer,
intent(in) :: dim
613 do iop = 1, this%nops
614 call symm_op_build_cartesian(this%ops(iop), latt, dim)
621 type(spglibdataset) function
symmetries_get_spg_dataset(namespace, space, latt, n_sites, site_pos, site_type) result(spg_dataset)
622 type(namespace_t),
intent(in) :: namespace
623 class(space_t),
intent(in) :: space
624 type(lattice_vectors_t),
intent(in) :: latt
625 integer,
intent(in) :: n_sites
626 real(real64),
intent(in) :: site_pos(:,:)
627 integer,
intent(in) :: site_type(1:n_sites)
629 integer :: isite, idir, dim4syms
630 real(real64),
allocatable :: position(:, :)
631 real(real64) :: lattice(1:3, 1:3)
635 assert(space%is_periodic())
637 dim4syms = min(3, space%dim)
639 safe_allocate(position(1:3, 1:n_sites))
641 do isite = 1, n_sites
642 position(1:3,isite) = m_zero
645 position(1:dim4syms, isite) = latt%cart_to_red(site_pos(1:dim4syms, isite))
646 position(1:dim4syms, isite) = position(1:dim4syms, isite) - m_half
647 do idir = 1, dim4syms
648 position(idir, isite) = position(idir, isite) - anint(position(idir, isite))
650 position(1:dim4syms, isite) = position(1:dim4syms,isite) + m_half
656 lattice(1:space%periodic_dim, 1:space%periodic_dim) = latt%rlattice(1:space%periodic_dim, 1:space%periodic_dim)
658 lattice(:,:) = transpose(lattice(:,:))
661 do idir = space%periodic_dim + 1, 3
662 if (idir <= space%dim)
then
663 lattice(idir, idir) = m_two*(maxval(site_pos(idir, :)) - minval(site_pos(idir, :))) + m_one
665 lattice(idir, idir) = m_one
669 spg_dataset = spg_get_dataset(lattice, position, site_type, n_sites,
symprec)
670 if (spg_dataset%spglib_error /= 0)
then
671 message(1) =
"Symmetry analysis failed in spglib. Disabling symmetries."
672 call messages_warning(1, namespace=namespace)
674 do isite = 1, n_sites
675 write(message(1),
'(a,i6,a,3f12.6,a,3f12.6)')
'type ', site_type(isite), &
676 ' reduced coords ', position(:, isite),
' cartesian coords ', site_pos(:, isite)
677 call messages_info(1, namespace=namespace)
680 safe_deallocate_a(position)
NOTE: unfortunately, these routines use global variables shared among them.
real(real64), parameter, public m_zero
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
This module is intended to contain "only mathematical" functions and procedures.
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
subroutine, public messages_experimental(name, namespace)
subroutine, public messages_info(no_lines, iunit, debug_only, stress, all_nodes, namespace)
logical function mpi_grp_is_root(grp)
Is the current MPI process of grpcomm, root.
type(mpi_grp_t), public mpi_world
integer function, public parse_block(namespace, name, blk, check_varinfo_)
type(spglibspacegrouptype) function, public spg_get_spacegroup_type(hall_number)
subroutine, public symm_op_copy(inp, outp)
logical pure function, public symm_op_has_translation(this, prec)
real(real64), parameter, public tol_translation
subroutine, public symm_op_init(this, rot, latt, dim, trans)
subroutine, public symmetries_update_lattice_vectors(this, latt, dim)
Updates the symmetry operations when lattice vectors are updated.
subroutine, public symmetries_apply_kpoint_red(this, iop, aa, bb)
integer pure function, public symmetries_space_group_number(this)
integer pure function, public symmetries_identity_index(this)
type(symmetries_t) function symmetries_constructor(namespace, space, latt, n_sites, site_pos, site_type, spherical_site)
subroutine, public symmetries_write_info(this, space, iunit, namespace)
real(real64), public symprec
integer pure function, public symmetries_number(this)
subroutine symmetries_copy(lhs, rhs)
logical pure function, public symmetries_have_break_dir(this)
type(spglibdataset) function, public symmetries_get_spg_dataset(namespace, space, latt, n_sites, site_pos, site_type)
Returns the SpglibDataset for the system.
subroutine symmetries_finalizer(this)
subroutine init_identity()