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
299 call symm_op_init(tmpop, spg_dataset%rotations(1:3, 1:3, iop), latt, dim4syms, spg_dataset%translations(1:3, iop))
302 if( all(abs(this%breakdir) <
m_epsilon) )
then
304 this%nops = this%nops + 1
307 this%nops_nonsymmorphic = this%nops_nonsymmorphic + 1
308 call symm_op_copy(tmpop, this%non_symmorphic_ops(this%nops_nonsymmorphic))
313 this%nops = this%nops + 1
338 do isite = 1, n_sites
341 rsite = latt%fold_into_cell(rsite)
344 do isite_symm = 1, n_sites
345 if (all(abs(rsite - site_pos(:, isite_symm)) < symprec))
exit
348 if (isite_symm > n_sites)
then
349 write(
message(1),
'(a,i6)')
'Internal error: could not find symmetric partner for atom number', isite
350 write(
message(2),
'(a,i3,a)')
'with symmetry operation number ', iop,
'.'
358 do iop = 1, this%nops_nonsymmorphic
359 do isite = 1, n_sites
362 rsite = latt%fold_into_cell(rsite)
365 do isite_symm = 1, n_sites
366 if (all(abs(rsite - site_pos(:, isite_symm)) < symprec))
exit
369 if (isite_symm > n_sites)
then
370 write(
message(1),
'(a,i6)')
'Internal error: could not find symmetric partner for atom number', isite
371 write(
message(2),
'(a,i3,a)')
'with non-symmorphic symmetry operation number ', iop,
'.'
386 safe_allocate(this%ops(1))
389 this%nops_nonsymmorphic = 0
408 safe_allocate(lhs%ops(1:rhs%nops))
413 safe_allocate(lhs%non_symmorphic_ops(1:rhs%nops_nonsymmorphic))
414 do iop = 1, rhs%nops_nonsymmorphic
415 call symm_op_copy(rhs%non_symmorphic_ops(iop), lhs%non_symmorphic_ops(iop))
417 lhs%nops_nonsymmorphic = rhs%nops_nonsymmorphic
418 lhs%breakdir = rhs%breakdir
419 lhs%periodic_dim = rhs%periodic_dim
420 lhs%space_group = rhs%space_group
421 lhs%any_non_spherical = rhs%any_non_spherical
422 lhs%symmetries_compute = rhs%symmetries_compute
423 lhs%group_name = rhs%group_name
424 lhs%group_elements = rhs%group_elements
425 lhs%symbol = rhs%symbol
426 lhs%schoenflies = rhs%schoenflies
438 safe_deallocate_a(this%ops)
439 safe_deallocate_a(this%non_symmorphic_ops)
456 integer,
intent(in) :: iop
457 real(real64),
intent(in) :: aa(1:3)
458 real(real64),
intent(out) :: bb(1:3)
462 assert(iop /= 0 .and. abs(iop) <= this%nops)
466 bb(1:3) = symm_op_apply_transpose_red(this%ops(abs(iop)), -aa(1:3))
468 bb(1:3) = symm_op_apply_transpose_red(this%ops(abs(iop)), aa(1:3))
476 integer pure function symmetries_space_group_number(this) result(number)
479 number = this%space_group
484 logical pure function symmetries_have_break_dir(this) result(have)
487 have = any(abs(this%breakdir(1:3)) > m_epsilon)
492 integer pure function symmetries_identity_index(this) result(index)
497 do iop = 1, this%nops
498 if (symm_op_is_identity(this%ops(iop)))
then
509 class(space_t),
intent(in) :: space
510 integer,
optional,
intent(in) :: iunit
511 type(namespace_t),
optional,
intent(in) :: namespace
517 call messages_print_with_emphasis(msg=
'Symmetries', iunit=iunit, namespace=namespace)
519 if (this%any_non_spherical)
then
520 message(1) =
"Symmetries are disabled since non-spherically symmetric species may be present."
521 call messages_info(1,iunit = iunit, namespace=namespace)
522 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
527 if (.not. this%symmetries_compute)
then
528 message(1) =
"Symmetries have been disabled by SymmetriesCompute = false."
529 call messages_info(1, iunit=iunit, namespace=namespace)
530 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
535 if (space%periodic_dim == 0)
then
537 if (mpi_grp_is_root(mpi_world))
then
538 if (this%symmetries_compute)
then
539 call messages_write(
'Symmetry elements : '//trim(this%group_elements), new_line = .
true.)
540 call messages_write(
'Symmetry group : '//trim(this%group_name))
541 call messages_info(iunit=iunit, namespace=namespace)
545 write(message(1),
'(a, i4)')
'Space group No. ', this%space_group
546 write(message(2),
'(2a)')
'International: ', trim(this%symbol)
547 write(message(3),
'(2a)')
'Schoenflies: ', trim(this%schoenflies)
548 call messages_info(3, iunit=iunit, namespace=namespace)
550 write(message(1),
'(a,i5,a)')
'Info: The system has ', this%nops,
' symmorphic symmetries that can be used.'
551 call messages_info(1, iunit=iunit, namespace=namespace)
553 write(message(1),
'(a7,a31,12x,a33)')
'Index',
'Rotation matrix',
'Fractional translations'
554 call messages_info(1, iunit=iunit, namespace=namespace)
555 do iop = 1, this%nops
558 if (space%dim == 1)
then
559 write(message(1),
'(i5,1x,a,2x,1(1i4,2x),1f12.6)') iop,
':', symm_op_rotation_matrix_red(this%ops(iop)), &
560 symm_op_translation_vector_red(this%ops(iop))
562 if (space%dim == 2)
then
563 write(message(1),
'(i5,1x,a,2x,2(2i4,2x),2f12.6)') iop,
':', symm_op_rotation_matrix_red(this%ops(iop)), &
564 symm_op_translation_vector_red(this%ops(iop))
566 if (space%dim == 3)
then
567 write(message(1),
'(i5,1x,a,2x,3(3i4,2x),3f12.6)') iop,
':', symm_op_rotation_matrix_red(this%ops(iop)), &
568 symm_op_translation_vector_red(this%ops(iop))
570 call messages_info(1, iunit=iunit, namespace=namespace)
573 write(message(1),
'(a,i5,a)')
'Info: The system also has ', this%nops_nonsymmorphic, &
574 ' nonsymmorphic symmetries (not used for electrons).'
575 call messages_info(1, iunit=iunit, namespace=namespace)
576 do iop = 1, this%nops_nonsymmorphic
579 if (space%dim == 1)
then
580 write(message(1),
'(i5,1x,a,2x,1(1i4,2x),1f12.6)') iop,
':', symm_op_rotation_matrix_red(this%non_symmorphic_ops(iop)), &
581 symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
583 if (space%dim == 2)
then
584 write(message(1),
'(i5,1x,a,2x,2(2i4,2x),2f12.6)') iop,
':', symm_op_rotation_matrix_red(this%non_symmorphic_ops(iop)), &
585 symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
587 if (space%dim == 3)
then
588 write(message(1),
'(i5,1x,a,2x,3(3i4,2x),3f12.6)') iop,
':', symm_op_rotation_matrix_red(this%non_symmorphic_ops(iop)), &
589 symm_op_translation_vector_red(this%non_symmorphic_ops(iop))
591 call messages_info(1, iunit=iunit, namespace=namespace)
594 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
603 type(lattice_vectors_t),
intent(in) :: latt
604 integer,
intent(in) :: dim
610 do iop = 1, this%nops
611 call symm_op_build_cartesian(this%ops(iop), latt, dim)
618 type(spglibdataset) function
symmetries_get_spg_dataset(namespace, space, latt, n_sites, site_pos, site_type) result(spg_dataset)
619 type(namespace_t),
intent(in) :: namespace
620 class(space_t),
intent(in) :: space
621 type(lattice_vectors_t),
intent(in) :: latt
622 integer,
intent(in) :: n_sites
623 real(real64),
intent(in) :: site_pos(:,:)
624 integer,
intent(in) :: site_type(1:n_sites)
626 integer :: isite, idir, dim4syms
627 real(real64),
allocatable :: position(:, :)
628 real(real64) :: lattice(1:3, 1:3)
632 assert(space%is_periodic())
634 dim4syms = min(3, space%dim)
636 safe_allocate(position(1:3, 1:n_sites))
638 do isite = 1, n_sites
639 position(1:3,isite) = m_zero
642 position(1:dim4syms, isite) = latt%cart_to_red(site_pos(1:dim4syms, isite))
643 position(1:dim4syms, isite) = position(1:dim4syms, isite) - m_half
644 do idir = 1, dim4syms
645 position(idir, isite) = position(idir, isite) - anint(position(idir, isite))
647 position(1:dim4syms, isite) = position(1:dim4syms,isite) + m_half
653 lattice(1:space%periodic_dim, 1:space%periodic_dim) = latt%rlattice(1:space%periodic_dim, 1:space%periodic_dim)
655 lattice(:,:) = transpose(lattice(:,:))
658 do idir = space%periodic_dim + 1, 3
659 if (idir <= space%dim)
then
660 lattice(idir, idir) = m_two*(maxval(site_pos(idir, :)) - minval(site_pos(idir, :))) + m_one
662 lattice(idir, idir) = m_one
666 spg_dataset = spg_get_dataset(lattice, position, site_type, n_sites,
symprec)
667 if (spg_dataset%spglib_error /= 0)
then
668 message(1) =
"Symmetry analysis failed in spglib. Disabling symmetries."
669 call messages_warning(1, namespace=namespace)
671 do isite = 1, n_sites
672 write(message(1),
'(a,i6,a,3f12.6,a,3f12.6)')
'type ', site_type(isite), &
673 ' reduced coords ', position(:, isite),
' cartesian coords ', site_pos(:, isite)
674 call messages_info(1, namespace=namespace)
677 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()