Octopus
centergeom.F90
Go to the documentation of this file.
1!! Copyright (C) 2002-2006 M. Marques, A. Castro, A. Rubio, G. Bertsch
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
23 use global_oct_m
24 use io_oct_m
25 use ions_oct_m
27 use mpi_oct_m
29 use parser_oct_m
31 use unit_oct_m
33
34 implicit none
35
36contains
37
38 subroutine centergeom_main() bind(c)
39 integer :: ierr
40
42
43 call getopt_init(ierr)
44 if (ierr == 0) call getopt_center_geom()
45 call getopt_end()
46
47 call parser_init()
48
49 call messages_init()
50
51 call io_init()
54
55 call center_geo()
56
58 call io_end()
59 call messages_end()
60
61 call parser_end()
62
63 call global_end()
64
65 contains
66
67 subroutine center_geo()
68
69 integer, parameter :: &
70 NONE = 0, &
71 inertia = 1, &
72 pseudo = 2, &
73 large = 3
74
75 type(ions_t), pointer :: ions
76 real(real64), allocatable :: center(:), x1(:), x2(:), to(:)
77 integer :: axis_type, idir, default
78 type(block_t) :: blk
79
81
82 if (ions%space%is_periodic()) then
83 message(1) = "oct-center-geom utility does not work for periodic systems."
84 call messages_fatal(1, namespace=ions%namespace)
85 end if
86
87 safe_allocate(center(1:ions%space%dim))
88 safe_allocate(x1(1:ions%space%dim))
89 safe_allocate(x2(1:ions%space%dim))
90 safe_allocate(to(1:ions%space%dim))
91
92 if (parse_is_defined(ions%namespace, 'BoxCenter')) then
93 call messages_not_implemented("The centergeom utitlity assumes the center of the box "// &
94 "at the origin and is not compatible with a shifted BoxCenter")
95 end if
96
97 ! is there something to do
98 if (ions%natoms > 1) then
99
100 !%Variable MainAxis
101 !%Type block
102 !%Section Utilities::oct-center-geom
103 !%Description
104 !% A vector of reals defining the axis to which the molecule
105 !% should be aligned. If not present, the default value will
106 !% be the x-axis. For example in 3D:
107 !% <tt>
108 !% <br>%MainAxis
109 !% <br> 1 | 0 | 0
110 !% <br>%</tt>
111 !%End
112 if (parse_block(ions%namespace, 'MainAxis', blk) == 0) then
113 do idir = 1, ions%space%dim
114 call parse_block_float(blk, 0, idir - 1, to(idir))
115 end do
116 call parse_block_end(blk)
117 else
118 to(:) = m_zero
119 to(1) = m_one
120 end if
121 if (norm2(to) > m_epsilon) to = to / norm2(to)
122
123 write(message(1),'(a,6f15.6)') 'Using main axis ', to
124 call messages_info(1)
125
126 !%Variable AxisType
127 !%Type integer
128 !%Default inertia
129 !%Section Utilities::oct-center-geom
130 !%Description
131 !% After the structure is centered, it is also aligned to a set of orthogonal axes.
132 !% This variable decides which set of axes to use. Only implemented for 3D, in which case
133 !% the default is <tt>inertia</tt>; otherwise <tt>none</tt> is default and the only legal value.
134 !%Option none 0
135 !% Do not rotate. Will still give output regarding center of mass and moment of inertia.
136 !%Option inertia 1
137 !% The axis of inertia.
138 !%Option pseudo_inertia 2
139 !% Pseudo-axis of inertia, calculated considering all species to have equal mass.
140 !%Option large_axis 3
141 !% The larger axis of the molecule.
142 !%End
143 if (ions%space%dim == 3) then
144 default = inertia
145 else
146 default = none
147 end if
148 call parse_variable(ions%namespace, 'AxisType', default, axis_type)
149 call messages_print_var_option("AxisType", axis_type, namespace=ions%namespace)
150
151 if (ions%space%dim /= 3 .and. axis_type /= none) then
152 call messages_not_implemented("alignment to axes (AxisType /= none) in other than 3 dimensions", namespace=ions%namespace)
153 end if
154
155 select case (axis_type)
156 case (none, inertia, pseudo)
157 center = ions%center_of_mass(pseudo = (axis_type == pseudo))
158
159 write(message(1),'(3a,99f15.6)') 'Center of mass [', trim(units_abbrev(units_out%length)), '] = ', &
160 units_from_atomic(units_out%length, center)
161 call messages_info(1)
162
163 call ions%translate(center)
164 call ions%axis_inertia(x1, x2, pseudo = (axis_type == pseudo))
165 case (large)
166 center = ions%center()
167
168 write(message(1),'(3a,99f15.6)') 'Center [', trim(units_abbrev(units_out%length)), '] = ', &
169 units_from_atomic(units_out%length, center)
170 call messages_info(1)
171
172 call ions%translate(center)
173 call ions%axis_large(x1, x2)
174 case default
175 write(message(1), '(a,i2,a)') 'AxisType = ', axis_type, ' not known by Octopus.'
176 call messages_fatal(1, namespace=ions%namespace)
177 end select
178
179 write(message(1),'(a,99f15.6)') 'Found primary axis ', x1
180 write(message(2),'(a,99f15.6)') 'Found secondary axis ', x2
181 call messages_info(2)
182
183 if (axis_type /= none) then
184 call ions%rotate(x1, x2, to)
185 end if
186
187 end if
188
189 ! recenter
190 center = ions%center()
191 call ions%translate(center)
192
193 ! write adjusted geometry
194 call ions%write_xyz('./adjusted')
195
196 safe_deallocate_a(center)
197 safe_deallocate_a(x1)
198 safe_deallocate_a(x2)
199 safe_deallocate_a(to)
200 safe_deallocate_p(ions)
201
202 end subroutine center_geo
203 end subroutine centergeom_main
204end module centergeom_main_oct_m
205
206!! Local Variables:
207!! mode: f90
208!! coding: utf-8
209!! End:
subroutine center_geo()
Definition: centergeom.F90:140
subroutine centergeom_main()
Definition: centergeom.F90:111
This module provides an interface to the getopt C library, so that the command line arguments can be ...
subroutine, public getopt_init(ierr)
Initializes the getopt machinery. Must be called before attempting to parse the options....
subroutine, public getopt_end
subroutine, public global_end()
Finalise parser varinfo file, and MPI.
Definition: global.F90:500
real(real64), parameter, public m_zero
Definition: global.F90:173
type(mpi_comm), parameter, public serial_dummy_comm
Alias MPI_COMM_UNDEFINED for the specific use case of initialising Octopus utilities with no MPI supp...
Definition: global.F90:268
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:438
real(real64), parameter, public m_epsilon
Definition: global.F90:189
real(real64), parameter, public m_one
Definition: global.F90:174
Definition: io.F90:93
subroutine, public io_init(defaults)
If the argument defaults is present and set to true, then the routine will not try to read anything f...
Definition: io.F90:142
subroutine, public io_end()
Definition: io.F90:248
subroutine, public messages_end()
Definition: messages.F90:249
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1048
subroutine, public messages_init(output_dir)
Definition: messages.F90:196
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_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
type(namespace_t), public global_namespace
Definition: namespace.F90:112
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:440
subroutine, public parser_init()
Initialise the Octopus parser.
Definition: parser.F90:387
subroutine, public parser_end()
End the Octopus parser.
Definition: parser.F90:419
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 profiling_end(namespace)
Definition: profiling.F90:455
subroutine, public profiling_init(namespace)
Create profiling subdirectory.
Definition: profiling.F90:264
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:111
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:202
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
subroutine, public unit_system_init(namespace)