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
21program centergeom
23 use global_oct_m
24 use io_oct_m
25 use ions_oct_m
28 use parser_oct_m
30 use unit_oct_m
32
33 implicit none
34
35 integer :: ierr
36
38
39 call getopt_init(ierr)
40 if (ierr == 0) call getopt_center_geom()
41 call getopt_end()
42
43 call parser_init()
44
45 call messages_init()
46
47 call io_init()
50
51 call center_geo()
52
54 call io_end()
55 call messages_end()
56
57 call parser_end()
58
59 call global_end()
60
61contains
62
63 subroutine center_geo()
64
65 integer, parameter :: &
66 NONE = 0, &
67 inertia = 1, &
68 pseudo = 2, &
69 large = 3
70
71 type(ions_t), pointer :: ions
72 real(real64), allocatable :: center(:), x1(:), x2(:), to(:)
73 integer :: axis_type, idir, default
74 type(block_t) :: blk
75
77
78 if (ions%space%is_periodic()) then
79 message(1) = "oct-center-geom utility does not work for periodic systems."
80 call messages_fatal(1, namespace=ions%namespace)
81 end if
82
83 safe_allocate(center(1:ions%space%dim))
84 safe_allocate(x1(1:ions%space%dim))
85 safe_allocate(x2(1:ions%space%dim))
86 safe_allocate(to(1:ions%space%dim))
87
88 if (parse_is_defined(ions%namespace, 'BoxCenter')) then
89 call messages_not_implemented("The centergeom utitlity assumes the center of the box "// &
90 "at the origin and is not compatible with a shifted BoxCenter")
91 end if
92
93 ! is there something to do
94 if (ions%natoms > 1) then
95
96 !%Variable MainAxis
97 !%Type block
98 !%Section Utilities::oct-center-geom
99 !%Description
100 !% A vector of reals defining the axis to which the molecule
101 !% should be aligned. If not present, the default value will
102 !% be the x-axis. For example in 3D:
103 !% <tt>
104 !% <br>%MainAxis
105 !% <br> 1 | 0 | 0
106 !% <br>%</tt>
107 !%End
108 if (parse_block(ions%namespace, 'MainAxis', blk) == 0) then
109 do idir = 1, ions%space%dim
110 call parse_block_float(blk, 0, idir - 1, to(idir))
111 end do
112 call parse_block_end(blk)
113 else
114 to(:) = m_zero
115 to(1) = m_one
116 end if
117 to = to / norm2(to)
118
119 write(message(1),'(a,6f15.6)') 'Using main axis ', to
120 call messages_info(1)
121
122 !%Variable AxisType
123 !%Type integer
124 !%Default inertia
125 !%Section Utilities::oct-center-geom
126 !%Description
127 !% After the structure is centered, it is also aligned to a set of orthogonal axes.
128 !% This variable decides which set of axes to use. Only implemented for 3D, in which case
129 !% the default is <tt>inertia</tt>; otherwise <tt>none</tt> is default and the only legal value.
130 !%Option none 0
131 !% Do not rotate. Will still give output regarding center of mass and moment of inertia.
132 !%Option inertia 1
133 !% The axis of inertia.
134 !%Option pseudo_inertia 2
135 !% Pseudo-axis of inertia, calculated considering all species to have equal mass.
136 !%Option large_axis 3
137 !% The larger axis of the molecule.
138 !%End
139 if (ions%space%dim == 3) then
140 default = inertia
141 else
142 default = none
143 end if
144 call parse_variable(ions%namespace, 'AxisType', default, axis_type)
145 call messages_print_var_option("AxisType", axis_type, namespace=ions%namespace)
146
147 if (ions%space%dim /= 3 .and. axis_type /= none) then
148 call messages_not_implemented("alignment to axes (AxisType /= none) in other than 3 dimensions", namespace=ions%namespace)
149 end if
150
151 select case (axis_type)
152 case (none, inertia, pseudo)
153 center = ions%center_of_mass(pseudo = (axis_type == pseudo))
154
155 write(message(1),'(3a,99f15.6)') 'Center of mass [', trim(units_abbrev(units_out%length)), '] = ', &
157 call messages_info(1)
158
159 call ions%translate(center)
160 call ions%axis_inertia(x1, x2, pseudo = (axis_type == pseudo))
161 case (large)
162 center = ions%center()
163
164 write(message(1),'(3a,99f15.6)') 'Center [', trim(units_abbrev(units_out%length)), '] = ', &
165 units_from_atomic(units_out%length, center)
166 call messages_info(1)
167
168 call ions%translate(center)
169 call ions%axis_large(x1, x2)
170 case default
171 write(message(1), '(a,i2,a)') 'AxisType = ', axis_type, ' not known by Octopus.'
172 call messages_fatal(1, namespace=ions%namespace)
173 end select
174
175 write(message(1),'(a,99f15.6)') 'Found primary axis ', x1
176 write(message(2),'(a,99f15.6)') 'Found secondary axis ', x2
177 call messages_info(2)
178
179 if (axis_type /= none) then
180 call ions%rotate(x1, x2, to)
181 end if
182
183 end if
184
185 ! recenter
186 center = ions%center()
187 call ions%translate(center)
188
189 ! write adjusted geometry
190 call ions%write_xyz('./adjusted')
191
192 safe_deallocate_a(center)
193 safe_deallocate_a(x1)
194 safe_deallocate_a(x2)
195 safe_deallocate_a(to)
196 safe_deallocate_p(ions)
197
198 end subroutine center_geo
199
200end program centergeom
201
202!! Local Variables:
203!! mode: f90
204!! coding: utf-8
205!! End:
subroutine center_geo()
Definition: centergeom.F90:157
program centergeom
Definition: centergeom.F90:114
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:381
real(real64), parameter, public m_zero
Definition: global.F90:187
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:264
subroutine, public init_octopus_globals(comm)
Initialise Octopus-specific global constants and files. This routine performs no initialisation calls...
Definition: global.F90:353
real(real64), parameter, public m_one
Definition: global.F90:188
Definition: io.F90:114
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:166
subroutine, public io_end()
Definition: io.F90:265
subroutine, public messages_end()
Definition: messages.F90:277
subroutine, public messages_not_implemented(feature, namespace)
Definition: messages.F90:1125
subroutine, public messages_init(output_dir)
Definition: messages.F90:224
subroutine, public messages_info(no_lines, iunit, verbose_limit, stress, all_nodes, namespace)
Definition: messages.F90:624
character(len=256), dimension(max_lines), public message
to be output by fatal, warning
Definition: messages.F90:160
subroutine, public messages_fatal(no_lines, only_root_writes, namespace)
Definition: messages.F90:420
type(namespace_t), public global_namespace
Definition: namespace.F90:132
logical function, public parse_is_defined(namespace, name)
Definition: parser.F90:502
subroutine, public parser_init()
Initialise the Octopus parser.
Definition: parser.F90:450
subroutine, public parser_end()
End the Octopus parser.
Definition: parser.F90:481
integer function, public parse_block(namespace, name, blk, check_varinfo_)
Definition: parser.F90:618
subroutine, public profiling_end(namespace)
Definition: profiling.F90:413
subroutine, public profiling_init(namespace)
Create profiling subdirectory.
Definition: profiling.F90:255
brief This module defines the class unit_t which is used by the unit_systems_oct_m module.
Definition: unit.F90:132
character(len=20) pure function, public units_abbrev(this)
Definition: unit.F90:223
This module defines the unit system, used for input and output.
type(unit_system_t), public units_out
subroutine, public unit_system_init(namespace)