25 use,
intrinsic :: iso_fortran_env
54 type(symm_op_t),
allocatable,
public :: ops(:)
55 integer,
public :: nops = 0
56 real(real64) :: breakdir(1:3)
57 integer,
public :: periodic_dim
58 integer :: space_group
59 logical :: any_non_spherical
60 logical :: symmetries_compute = .false.
61 character(len=6) :: group_name =
""
62 character(len=30) :: group_elements =
""
63 character(len=11) :: symbol =
""
64 character(len=7) :: schoenflies =
""
66 type(symm_op_t),
allocatable,
public :: non_symmorphic_ops(:)
67 integer,
public :: nops_nonsymmorphic = 0
70 generic ::
assignment(=) => copy
74 real(real64),
parameter,
public :: default_symprec = 1.e-5_real64
75 real(real64),
public :: symprec
80 use,
intrinsic :: iso_fortran_env
81 integer,
intent(in) :: natoms
82 integer,
intent(in) :: types
83 real(real64),
intent(in) :: positions
84 integer,
intent(in) :: verbosity
85 integer,
intent(out) :: point_group
89 integer,
intent(in) :: point_group
90 character(len=*),
intent(out) :: name
94 integer,
intent(in) :: point_group
95 character(len=*),
intent(out) :: elements
108 function symmetries_constructor(namespace, space, latt, n_sites, site_pos, site_type, spherical_site)
result(this)
109 type(namespace_t),
intent(in) :: namespace
110 class(space_t),
intent(in) :: space
111 type(lattice_vectors_t),
intent(in) :: latt
112 integer,
intent(in) :: n_sites
113 real(real64),
intent(in) :: site_pos(:,:)
114 integer,
intent(in) :: site_type(1:n_sites)
115 logical,
intent(in) :: spherical_site(:)
116 type(symmetries_t) :: this
119 integer :: idir, isite, isite_symm, iop, verbosity, point_group
120 real(real64) :: lattice(1:3, 1:3)
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)
213 safe_allocate(position(1:3, 1:n_sites))
215 do isite = 1, n_sites
216 position(1:3,isite) =
m_zero
219 position(1:dim4syms, isite) = latt%cart_to_red(site_pos(1:dim4syms, isite))
220 position(1:dim4syms, isite) = position(1:dim4syms, isite) -
m_half
221 do idir = 1, dim4syms
222 position(idir, isite) = position(idir, isite) - anint(position(idir, isite))
224 position(1:dim4syms, isite) = position(1:dim4syms,isite) +
m_half
230 lattice(1:space%periodic_dim, 1:space%periodic_dim) = latt%rlattice(1:space%periodic_dim, 1:space%periodic_dim)
232 lattice(:,:) = transpose(lattice(:,:))
235 do idir = space%periodic_dim + 1, 3
236 if (idir <= space%dim)
then
237 lattice(idir, idir) =
m_two*(maxval(site_pos(idir, :)) - minval(site_pos(idir, :))) +
m_one
239 lattice(idir, idir) =
m_one
243 spg_dataset =
spg_get_dataset(lattice, position, site_type, n_sites, symprec)
244 if (spg_dataset%spglib_error /= 0)
then
245 message(1) =
"Symmetry analysis failed in spglib. Disabling symmetries."
248 do isite = 1, n_sites
249 write(
message(1),
'(a,i6,a,3f12.6,a,3f12.6)')
'type ', site_type(isite), &
250 ' reduced coords ', position(:, isite),
' cartesian coords ', site_pos(:, isite)
259 this%space_group = spg_dataset%spacegroup_number
260 this%symbol = spg_dataset%international_symbol
262 this%schoenflies = spg_spacegroup%schoenflies
264 do iop = 1, spg_dataset%n_operations
266 spg_dataset%rotations(:,:,iop) = transpose(spg_dataset%rotations(:,:,iop))
268 spg_dataset%translations(:, iop) = spg_dataset%translations(:, iop) - &
269 anint(spg_dataset%translations(:, iop) +
m_half * symprec)
275 is_supercell = (spg_dataset%n_operations > 48)
276 found_identity = .false.
278 do iop = 1, spg_dataset%n_operations
279 if (all(spg_dataset%rotations(1:3, 1:3, iop) == identity(1:3, 1:3)))
then
280 found_identity = .
true.
281 if (any(abs(spg_dataset%translations(1:3, iop)) > real(symprec, real64) ))
then
282 is_supercell = .
true.
283 write(
message(1),
'(a,3f12.6)')
'Identity has a fractional translation ', spg_dataset%translations(1:3, iop)
288 if (.not. found_identity)
then
289 message(1) =
"Symmetries internal error: Identity is missing from symmetry operations."
293 if (is_supercell)
then
294 message(1) =
"Disabling fractional translations. System appears to be a supercell."
312 this%breakdir(1:3) =
m_zero
314 if (
parse_block(namespace,
'SymmetryBreakDir', blk) == 0)
then
316 do idir = 1, dim4syms
324 safe_allocate(this%ops(1:spg_dataset%n_operations))
325 safe_allocate(this%non_symmorphic_ops(1:spg_dataset%n_operations))
331 this%nops_nonsymmorphic = 0
332 do iop = 1, spg_dataset%n_operations
333 call symm_op_init(tmpop, spg_dataset%rotations(1:3, 1:3, iop), latt, dim4syms, spg_dataset%translations(1:3, iop))
336 if( all(abs(this%breakdir) <
m_epsilon) )
then
338 this%nops = this%nops + 1
341 this%nops_nonsymmorphic = this%nops_nonsymmorphic + 1
342 call symm_op_copy(tmpop, this%non_symmorphic_ops(this%nops_nonsymmorphic))
347 this%nops = this%nops + 1
353 safe_deallocate_a(position)
372 do isite = 1, n_sites
375 rsite = latt%fold_into_cell(rsite)
378 do isite_symm = 1, n_sites
379 if (all(abs(rsite - site_pos(:, isite_symm)) < default_symprec))
exit
382 if (isite_symm > n_sites)
then
383 write(
message(1),
'(a,i6)')
'Internal error: could not find symmetric partner for atom number', isite
384 write(
message(2),
'(a,i3,a)')
'with symmetry operation number ', iop,
'.'
402 safe_allocate(this%ops(1))
405 this%nops_nonsymmorphic = 0
424 safe_allocate(lhs%ops(1:rhs%nops))
429 safe_allocate(lhs%non_symmorphic_ops(1:rhs%nops_nonsymmorphic))
430 do iop = 1, rhs%nops_nonsymmorphic
431 call symm_op_copy(rhs%non_symmorphic_ops(iop), lhs%non_symmorphic_ops(iop))
433 lhs%nops_nonsymmorphic = rhs%nops_nonsymmorphic
434 lhs%breakdir = rhs%breakdir
435 lhs%periodic_dim = rhs%periodic_dim
436 lhs%space_group = rhs%space_group
437 lhs%any_non_spherical = rhs%any_non_spherical
438 lhs%symmetries_compute = rhs%symmetries_compute
439 lhs%group_name = rhs%group_name
440 lhs%group_elements = rhs%group_elements
441 lhs%symbol = rhs%symbol
442 lhs%schoenflies = rhs%schoenflies
454 safe_deallocate_a(this%ops)
455 safe_deallocate_a(this%non_symmorphic_ops)
472 integer,
intent(in) :: iop
473 real(real64),
intent(in) :: aa(1:3)
474 real(real64),
intent(out) :: bb(1:3)
478 assert(iop /= 0 .and. abs(iop) <= this%nops)
482 bb(1:3) = symm_op_apply_transpose_red(this%ops(abs(iop)), -aa(1:3))
484 bb(1:3) = symm_op_apply_transpose_red(this%ops(abs(iop)), aa(1:3))
492 integer pure function symmetries_space_group_number(this) result(number)
495 number = this%space_group
500 logical pure function symmetries_have_break_dir(this) result(have)
503 have = any(abs(this%breakdir(1:3)) > m_epsilon)
508 integer pure function symmetries_identity_index(this) result(index)
513 do iop = 1, this%nops
514 if (symm_op_is_identity(this%ops(iop)))
then
525 class(space_t),
intent(in) :: space
526 integer,
optional,
intent(in) :: iunit
527 type(namespace_t),
optional,
intent(in) :: namespace
533 call messages_print_with_emphasis(msg=
'Symmetries', iunit=iunit, namespace=namespace)
535 if (this%any_non_spherical)
then
536 message(1) =
"Symmetries are disabled since non-spherically symmetric species may be present."
537 call messages_info(1,iunit = iunit, namespace=namespace)
538 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
543 if (.not. this%symmetries_compute)
then
544 message(1) =
"Symmetries have been disabled by SymmetriesCompute = false."
545 call messages_info(1, iunit=iunit, namespace=namespace)
546 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
551 if (space%periodic_dim == 0)
then
553 if (mpi_grp_is_root(mpi_world))
then
554 if (this%symmetries_compute)
then
555 call messages_write(
'Symmetry elements : '//trim(this%group_elements), new_line = .
true.)
556 call messages_write(
'Symmetry group : '//trim(this%group_name))
557 call messages_info(iunit=iunit, namespace=namespace)
561 write(message(1),
'(a, i4)')
'Space group No. ', this%space_group
562 write(message(2),
'(2a)')
'International: ', trim(this%symbol)
563 write(message(3),
'(2a)')
'Schoenflies: ', trim(this%schoenflies)
564 call messages_info(3, iunit=iunit, namespace=namespace)
566 write(message(1),
'(a7,a31,12x,a33)')
'Index',
'Rotation matrix',
'Fractional translations'
567 call messages_info(1, iunit=iunit, namespace=namespace)
568 do iop = 1, this%nops
571 if (space%dim == 1)
then
572 write(message(1),
'(i5,1x,a,2x,1(1i4,2x),1f12.6)') iop,
':', symm_op_rotation_matrix_red(this%ops(iop)), &
573 symm_op_translation_vector_red(this%ops(iop))
575 if (space%dim == 2)
then
576 write(message(1),
'(i5,1x,a,2x,2(2i4,2x),2f12.6)') iop,
':', symm_op_rotation_matrix_red(this%ops(iop)), &
577 symm_op_translation_vector_red(this%ops(iop))
579 if (space%dim == 3)
then
580 write(message(1),
'(i5,1x,a,2x,3(3i4,2x),3f12.6)') iop,
':', symm_op_rotation_matrix_red(this%ops(iop)), &
581 symm_op_translation_vector_red(this%ops(iop))
583 call messages_info(1, iunit=iunit, namespace=namespace)
585 write(message(1),
'(a,i5,a)')
'Info: The system has ', this%nops,
' symmetries that can be used.'
586 write(message(2),
'(a,i5,a)')
'Info: The system also has ', this%nops_nonsymmorphic, &
587 ' nonsymmorphic symmetries (not used).'
588 call messages_info(2, iunit=iunit, namespace=namespace)
590 call messages_print_with_emphasis(iunit=iunit, namespace=namespace)
599 type(lattice_vectors_t),
intent(in) :: latt
600 integer,
intent(in) :: dim
606 do iop = 1, this%nops
607 call symm_op_build_cartesian(this%ops(iop), latt, dim)
NOTE: unfortunately, these routines use global variables shared among them.
real(real64), parameter, public m_two
real(real64), parameter, public m_zero
real(real64), parameter, public m_epsilon
real(real64), parameter, public m_half
real(real64), parameter, public m_one
This module is intended to contain "only mathematical" functions and procedures.
subroutine, public messages_warning(no_lines, all_nodes, namespace)
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
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)
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(spglibdataset) function, public spg_get_dataset(lattice, position, types, num_atom, symprec)
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)
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)
integer pure function, public symmetries_number(this)
subroutine symmetries_copy(lhs, rhs)
logical pure function, public symmetries_have_break_dir(this)
subroutine symmetries_finalizer(this)
subroutine init_identity()