(git:936074a)
Loading...
Searching...
No Matches
cp_realspace_grid_cube.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief A wrapper around pw_to_cube() which accepts particle_list_type
10!> \author Ole Schuett
11! **************************************************************************************************
15 USE kinds, ONLY: dp
17 USE pw_types, ONLY: pw_r3d_rs_type
21#include "./base/base_uses.f90"
22
23 IMPLICIT NONE
24
25 PRIVATE
26
28
29 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_realspace_grid_cube'
30
31CONTAINS
32
33! **************************************************************************************************
34!> \brief ...
35!> \param pw ...
36!> \param unit_nr ...
37!> \param title ...
38!> \param particles ...
39!> \param zeff ...
40!> \param stride ...
41!> \param zero_tails ...
42!> \param silent minimal I/O
43!> \param mpi_io True if cube should be written in parallel using MPI
44! **************************************************************************************************
45 SUBROUTINE cp_pw_to_cube(pw, unit_nr, title, particles, zeff, stride, zero_tails, silent, mpi_io)
46 TYPE(pw_r3d_rs_type), INTENT(IN) :: pw
47 INTEGER, INTENT(IN) :: unit_nr
48 CHARACTER(*), INTENT(IN), OPTIONAL :: title
49 TYPE(particle_list_type), POINTER :: particles
50 REAL(kind=dp), DIMENSION(:), OPTIONAL :: zeff
51 INTEGER, DIMENSION(:), OPTIONAL, POINTER :: stride
52 LOGICAL, INTENT(IN), OPTIONAL :: zero_tails, silent, mpi_io
53
54 INTEGER :: i, n
55 INTEGER, ALLOCATABLE, DIMENSION(:) :: particles_z
56 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: particles_r
57 TYPE(particle_list_type), POINTER :: my_particles
58
59 NULLIFY (my_particles)
60 my_particles => particles
61 IF (ASSOCIATED(my_particles)) THEN
62 n = my_particles%n_els
63 ALLOCATE (particles_z(n))
64 ALLOCATE (particles_r(3, n))
65 DO i = 1, n
66 CALL get_atomic_kind(my_particles%els(i)%atomic_kind, z=particles_z(i))
67 particles_r(:, i) = my_particles%els(i)%r(:)
68 END DO
69
70 CALL pw_to_cube(pw=pw, unit_nr=unit_nr, title=title, &
71 particles_z=particles_z, particles_r=particles_r, &
72 particles_zeff=zeff, &
73 stride=stride, zero_tails=zero_tails, &
74 silent=silent, mpi_io=mpi_io)
75 ELSE
76 CALL pw_to_cube(pw=pw, unit_nr=unit_nr, title=title, &
77 stride=stride, zero_tails=zero_tails, &
78 silent=silent, mpi_io=mpi_io)
79 END IF
80
81 END SUBROUTINE cp_pw_to_cube
82
83! **************************************************************************************************
84!> \brief Prints grid in a simple format: X Y Z value
85!> \param pw ...
86!> \param unit_nr ...
87!> \param stride ...
88!> \param pw2 ...
89!> \par History
90!> Created [Vladimir Rybkin] (08.2017)
91! **************************************************************************************************
92 SUBROUTINE cp_pw_to_simple_volumetric(pw, unit_nr, stride, pw2)
93 TYPE(pw_r3d_rs_type), INTENT(IN) :: pw
94 INTEGER, INTENT(IN) :: unit_nr
95 INTEGER, DIMENSION(:), OPTIONAL, POINTER :: stride
96 TYPE(pw_r3d_rs_type), INTENT(IN), OPTIONAL :: pw2
97
98 IF (.NOT. PRESENT(pw2)) THEN
99 CALL pw_to_simple_volumetric(pw, unit_nr, stride)
100 ELSE
101 CALL pw_to_simple_volumetric(pw, unit_nr, stride, pw2)
102 END IF
103
104 END SUBROUTINE cp_pw_to_simple_volumetric
105
106! **************************************************************************************************
107!> \brief Thin wrapper around routine cube_to_pw
108!> \param grid pw to read from cube file
109!> \param filename name of cube file
110!> \param scaling scale values before storing
111!> \param silent minimal I/O
112!> \par History
113!> Created [Nico Holmberg] (09.2018)
114! **************************************************************************************************
115 SUBROUTINE cp_cube_to_pw(grid, filename, scaling, silent)
116 TYPE(pw_r3d_rs_type), INTENT(IN) :: grid
117 CHARACTER(len=*), INTENT(in) :: filename
118 REAL(kind=dp), INTENT(in) :: scaling
119 LOGICAL, INTENT(in), OPTIONAL :: silent
120
121 LOGICAL :: parallel_read
122
123 ! Determine whether to use MPI I/O for reading cube filename
124 parallel_read = .true.
125 ! Parallel routine falls back to stream read in serial mode,
126 ! but it has slight overhead compared to sequential read
127 ! Therefore, we use sequential version in serial mode
128 IF (grid%pw_grid%para%group%num_pe == 1) parallel_read = .false.
129 ! Check if MPI I/O was disabled in GLOBAL section
130 IF (.NOT. cp_mpi_io_get()) parallel_read = .false.
131
132 CALL cube_to_pw(grid, filename, scaling, parallel_read, silent=silent)
133
134 END SUBROUTINE cp_cube_to_pw
135
136END MODULE cp_realspace_grid_cube
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
logical function, public cp_mpi_io_get()
Gets flag which determines whether or not to use MPI I/O for I/O routines that have been parallized w...
A wrapper around pw_to_cube() which accepts particle_list_type.
subroutine, public cp_cube_to_pw(grid, filename, scaling, silent)
Thin wrapper around routine cube_to_pw.
subroutine, public cp_pw_to_simple_volumetric(pw, unit_nr, stride, pw2)
Prints grid in a simple format: X Y Z value.
subroutine, public cp_pw_to_cube(pw, unit_nr, title, particles, zeff, stride, zero_tails, silent, mpi_io)
...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
represent a simple array based list of the given type
Generate Gaussian cube files.
subroutine, public cube_to_pw(grid, filename, scaling, parallel_read, silent)
Computes the external density on the grid hacked from external_read_density.
subroutine, public pw_to_cube(pw, unit_nr, title, particles_r, particles_z, particles_zeff, stride, zero_tails, silent, mpi_io)
...
subroutine, public pw_to_simple_volumetric(pw, unit_nr, stride, pw2)
Prints a simple grid file: X Y Z value.