forked from slitvinov/packmol
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcenmass.f
114 lines (96 loc) · 3.01 KB
/
cenmass.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
c
c Written by Leandro Martínez, 2009-2011.
c Copyright (c) 2009-2011, Leandro Martínez, Jose Mario Martinez,
c Ernesto G. Birgin.
c
c This program is free software; you can redistribute it and/or
c modify it under the terms of the GNU General Public License
c as published by the Free Software Foundation; either version 2
c of the License, or (at your option) any later version.
c
c Subroutine cenmass
c
c Computes the center of mass of free molecules and
c for fixed molecules, if required.
c
subroutine cenmass(coor,amass,
+ ntype,nlines,
+ idfirst,natoms,
+ keyword,linestrut)
implicit none
include 'sizes.i'
character*200 keyword(maxlines,maxkeywords)
double precision cm(maxtype,3), totm(maxtype)
double precision amass(maxatom)
double precision coor(maxatom,3)
integer linestrut(maxtype,2)
integer k, iline, nlines
integer itype, ntype, iatom, idatom
integer idfirst(maxtype), natoms(maxtype)
logical domass(maxtype)
c Setting the molecules for which the center of mass is computed
do itype = 1, ntype
domass(itype) = .true.
end do
do iline = 1, nlines
if(keyword(iline,1).eq.'fixed') then
do itype = 1, ntype
if(iline.gt.linestrut(itype,1).and.
+ iline.lt.linestrut(itype,2)) then
domass(itype) = .false.
end if
end do
end if
end do
do iline = 1, nlines
if(keyword(iline,1).eq.'centerofmass'.or.
+ keyword(iline,1).eq.'center') then
do itype = 1, ntype
if(iline.gt.linestrut(itype,1).and.
+ iline.lt.linestrut(itype,2)) then
domass(itype) = .true.
end if
end do
end if
end do
c Computing the center of mass
do itype = 1, ntype
do k = 1, 3
cm(itype, k) = 0.d0
end do
end do
do itype = 1, ntype
totm(itype) = 0.d0
idatom = idfirst(itype) - 1
do iatom = 1, natoms(itype)
idatom = idatom + 1
totm(itype) = totm(itype) + amass(idatom)
end do
end do
do itype = 1, ntype
idatom = idfirst(itype) - 1
do iatom = 1, natoms(itype)
idatom = idatom + 1
do k = 1, 3
cm(itype, k) = cm(itype, k)
+ + coor(idatom, k)*amass(idatom)
end do
end do
do k = 1, 3
cm(itype, k) = cm(itype, k) / totm(itype)
end do
end do
c Putting molecules in their center of mass
do itype = 1, ntype
if(domass(itype)) then
idatom = idfirst(itype) - 1
do iatom = 1, natoms(itype)
idatom = idatom + 1
do k = 1, 3
coor(idatom, k) = coor(idatom, k) - cm(itype, k)
end do
end do
end if
end do
return
end