BraWl
Loading...
Searching...
No Matches
write_xyz.f90
Go to the documentation of this file.
1
12
13 use kinds
15 use constants
16 use shared_data
17 use analytics
18
19 implicit none
20
21 contains
22
40 subroutine xyz_writer(filename, configuration, setup, trajectory)
41 ! Simulation setup information
42 type(run_params), intent(in) :: setup
43
44 ! Data to write to file
45 !integer(array_int), dimension(:,:,:,:), allocatable, intent(in) :: configuration
46 integer(array_int), dimension(:,:,:,:), intent(in) :: configuration
47
48 ! Option to open existing xyz file and append new configuration to the end
49 logical, optional :: trajectory
50
51 ! Sizes of grid
52 integer, dimension(4) :: grid_sizes
53
54 ! Filename to which to write
55 character(len=*), intent(in) :: filename
56
57 integer :: n_particles, i, j, k, l
58 logical :: exist
59 real(real64), dimension(3) :: pos
60
61 n_particles = total_particle_count(setup, configuration)
62
63 grid_sizes = shape(configuration)
64
65 ! Check if we want to open new xyz, overwrite existing xyz or append existing xyz file
66 if (present(trajectory)) then
67
68 if (trajectory) then
69 inquire(file=filename, exist=exist)
70 if (exist) then
71 open(7, file=filename, status="old", position="append", action="write")
72 else
73 open(7, file=filename, status="new", action="write")
74 end if
75 end if
76
77 else ! open xyz (if exists, will ovrewrite)
78
79 open(unit=7, file=filename)
80
81 endif
82
83 write(7, *) n_particles
84
85 write(7,*) 'Lattice="',setup%lattice_parameter*setup%n_1, 0.0, 0.0 , &
86 & 0.0, setup%lattice_parameter*setup%n_2, 0.0 , &
87 & 0.0, 0.0, setup%lattice_parameter*setup%n_3, '"'
88
89! if (present(trajectory)) then
90! if (trajectory) then
91! write(7,*) 'Lattice="',setup%lattice_parameter*setup%n_1, 0.0, 0.0 , &
92! & 0.0, setup%lattice_parameter*setup%n_2, 0.0 , &
93! & 0.0, 0.0, setup%lattice_parameter*setup%n_3, '"'
94! end if
95! else
96! write(7,*) ''
97! end if
98
99 do i=1, grid_sizes(1)
100 do j=1, grid_sizes(2)
101 do k=1, grid_sizes(3)
102 do l=1, grid_sizes(4)
103 if (configuration(i,j,k,l) .eq. 0) cycle
104 pos = real(j-1)*setup%lattice_vectors(1,:) + &
105 real(k-1)*setup%lattice_vectors(2,:) + &
106 real(l-1)*setup%lattice_vectors(3,:) + &
107 real(i)*setup%basis_vectors
108 pos = pos*setup%lattice_parameter
109 write(7,*) setup%species_names(configuration(i,j,k,l)), pos(1),pos(2),pos(3)
110 end do
111 end do
112 end do
113 end do
114
115 close(unit=7)
116
117 end subroutine xyz_writer
118
119end module write_xyz
integer function, public total_particle_count(setup, config)
Function to count the total number of particles in the box.
subroutine xyz_writer(filename, configuration, setup, trajectory)
Subroutine to write xyz file
Definition write_xyz.f90:41
Derived type for parameters specifying general simulation parameters which are common to all sampling...