atomes 1.1.15
atomes: an atomic scale modeling tool box
Loading...
Searching...
No Matches
ogl_utils.c
Go to the documentation of this file.
1/* This file is part of the 'atomes' software
2
3'atomes' is free software: you can redistribute it and/or modify it under the terms
4of the GNU Affero General Public License as published by the Free Software Foundation,
5either version 3 of the License, or (at your option) any later version.
6
7'atomes' is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
8without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9See the GNU General Public License for more details.
10
11You should have received a copy of the GNU Affero General Public License along with 'atomes'.
12If not, see <https://www.gnu.org/licenses/>
13
14Copyright (C) 2022-2024 by CNRS and University of Strasbourg */
15
22/*
23* This file: 'ogl_utils.c'
24*
25* Contains:
26*
27
28 - 2D and 3D calculations utilities for distances and angles
29
30*
31* List of functions:
32
33 double arc_cos (double val);
34
35 distance distance_2d (atom * at, atom * bt);
36 distance distance_3d (cell_info * cell, int mdstep, atom * at, atom * bt);
37 angle angle_2d (atom * at, atom * bt, atom * ct);
38 angle angle_3d (cell_info * cell, int mdstep, atom * at, atom * bt, atom * ct);
39 angle dihedral_3d (cell_info * cell, int mdstep, atom * at, atom * bt, atom * ct, atom * dt);
40 angle inversion_3d (cell_info * cell, int mdstep, atom * at, atom * bt, atom * ct, atom * dt);
41
42*/
43
44#include "global.h"
45#include "interface.h"
46#include "glview.h"
47#include "dlp_field.h"
48
49extern gboolean field_color;
50extern ColRGBA init_color (int id, int numid);
51
61{
63 dist.pbc = FALSE;
64 dist.x = at -> x - bt -> x;
65 dist.y = at -> y - bt -> y;
66 dist.z = 0.0;
67 dist.length = sqrt(dist.x*dist.x + dist.y*dist.y);
68 return dist;
69}
70
81distance distance_3d (cell_info * cell, int mdstep, atom * at, atom * bt)
82{
84 double tmp;
85 vec3_t dij;
86 dist.pbc = FALSE;
87 dist.x = at -> x - bt -> x;
88 dist.y = at -> y - bt -> y;
89 dist.z = at -> z - bt -> z;
90 dist.length = sqrt(dist.x*dist.x + dist.y*dist.y + dist.z*dist.z);
91 if (cell -> pbc)
92 {
93 if (cell -> box[mdstep].param[1][0] == 90.0 && cell -> box[mdstep].param[1][1] == 90.0 && cell -> box[mdstep].param[1][2] == 90.0)
94 {
95 dij.x = dist.x - round((at -> x-bt -> x)/cell -> box[mdstep].param[0][0]) * cell -> box[mdstep].param[0][0];
96 dij.y = dist.y - round((at -> y-bt -> y)/cell -> box[mdstep].param[0][1]) * cell -> box[mdstep].param[0][1];
97 dij.z = dist.z - round((at -> z-bt -> z)/cell -> box[mdstep].param[0][2]) * cell -> box[mdstep].param[0][2];
98 }
99 else
100 {
101 vec3_t a = vec3(at -> x, at -> y, at -> z);
102 vec3_t b = vec3(bt -> x, bt -> y, bt -> z);
103 vec3_t af = m4_mul_coord (cell -> box[mdstep].cart_to_frac, a);
104 vec3_t bf = m4_mul_coord (cell -> box[mdstep].cart_to_frac, b);
105 vec3_t nij = v3_sub(af, bf);
106 nij.x -= round(nij.x);
107 nij.y -= round(nij.y);
108 nij.z -= round(nij.z);
109 dij = m4_mul_coord (cell -> box[mdstep].frac_to_cart, nij);
110 }
111 tmp = v3_length(dij);
112 if (dist.length - tmp > 0.001)
113 {
114 dist.pbc = TRUE;
115 dist.x = dij.x;
116 dist.y = dij.y;
117 dist.z = dij.z;
118 dist.length = tmp;
119 }
120 }
121 return dist;
122}
123
131double arc_cos (double val)
132{
133 if (val < -1.0)
134 {
135 return acos(-2.0 - val) * 180.0 / pi;
136 }
137 else if (val > 1.0)
138 {
139 return acos(2.0 - val) * 180.0 / pi;
140 }
141 else
142 {
143 return acos(val) * 180.0 / pi;
144 }
145}
146
156angle angle_2d (atom * at, atom * bt, atom * ct)
157{
158 angle theta;
159 distance dist_a = distance_2d (bt, at);
160 distance dist_b = distance_2d (bt, ct);
161 theta.pbc = FALSE;
162 double v = 0.0;
163 v = dist_a.x*dist_b.x + dist_a.y*dist_b.y;
164 theta.angle = arc_cos(v/(dist_a.length*dist_b.length));
165 return theta;
166}
167
179angle angle_3d (cell_info * cell, int mdstep, atom * at, atom * bt, atom * ct)
180{
181 angle theta;
182 distance dist_a = distance_3d (cell, mdstep, bt, at);
183 distance dist_b = distance_3d (cell, mdstep, bt, ct);
184 theta.pbc = FALSE;
185 if (dist_a.pbc || dist_b.pbc) theta.pbc = TRUE;
186 double v = 0.0;
187 v = dist_a.x*dist_b.x + dist_a.y*dist_b.y + dist_a.z*dist_b.z;
188 theta.angle = arc_cos(v/(dist_a.length*dist_b.length));
189 return theta;
190}
191
204angle dihedral_3d (cell_info * cell, int mdstep, atom * at, atom * bt, atom * ct, atom * dt)
205{
206 angle phi;
207 distance dist_a = distance_3d (cell, mdstep, at, bt);
208 distance dist_b = distance_3d (cell, mdstep, bt, ct);
209 distance dist_c = distance_3d (cell, mdstep, ct, dt);
210 vec3_t u, v;
211
212 if (dist_a.pbc || dist_b.pbc || dist_c.pbc) phi.pbc = TRUE;
213
214 u = vec3(dist_a.y*dist_b.z - dist_a.z*dist_b.y, dist_a.z*dist_b.x - dist_a.x*dist_b.z, dist_a.x*dist_b.y - dist_a.y*dist_b.x);
215 v = vec3(dist_b.y*dist_c.z - dist_b.z*dist_c.y, dist_b.z*dist_c.x - dist_b.x*dist_c.z, dist_b.x*dist_c.y - dist_b.y*dist_c.x);
216
217 if (v3_length(u) == 0.0 || v3_length(v) == 0.0)
218 {
219 phi.angle = 0.0;
220 }
221 else
222 {
223 phi.angle = arc_cos(v3_dot(u, v)/(v3_length(u)*v3_length(v)));
224 }
225 return phi;
226}
227
240angle inversion_3d (cell_info * cell, int mdstep, atom * at, atom * bt, atom * ct, atom * dt)
241{
242 angle inv;
243 distance dist_a = distance_3d (cell, mdstep, bt, at);
244 distance dist_b = distance_3d (cell, mdstep, ct, at);
245 distance dist_c = distance_3d (cell, mdstep, at, dt);
246 vec3_t u, v, w, x;
247
248 if (dist_a.pbc || dist_b.pbc || dist_c.pbc) inv.pbc = TRUE;
249
250 u = vec3(dist_b.x, dist_b.y, dist_b.z);
251 v = vec3(dist_c.x, dist_c.y, dist_c.z);
252 w = v3_cross (u, v);
253 x = vec3(dist_a.x, dist_a.y, dist_a.z);
254 if (v3_length(w) == 0.0 || v3_length(x) == 0.0)
255 {
256 inv.angle = 0.0;
257 }
258 else
259 {
260 inv.angle = fabs(90.0 - arc_cos(v3_dot(w, x)/(v3_length(w)*v3_length(x))));
261 }
262 return inv;
263}
gchar * param[2]
double dist
Definition d_measures.c:73
float val
Definition dlp_init.c:117
Variable declarations for the creation of the DL_POLY input file(s)
double pi
Definition global.c:195
Global variable declarations Global convenience function declarations Global data structure defin...
Variable declarations related to the OpenGL window Function declarations related to the OpenGL wind...
Messaging function declarations.
double z
Definition ogl_draw.c:57
double y
Definition ogl_draw.c:57
double x
Definition ogl_draw.c:57
angle dihedral_3d(cell_info *cell, int mdstep, atom *at, atom *bt, atom *ct, atom *dt)
dihedral between atom a, b, c and d in 3D
Definition ogl_utils.c:204
distance distance_2d(atom *at, atom *bt)
distance between atom a and b in 2D
Definition ogl_utils.c:60
double arc_cos(double val)
compute arc cosinus
Definition ogl_utils.c:131
angle angle_2d(atom *at, atom *bt, atom *ct)
angle between atom a, b and c in 2D
Definition ogl_utils.c:156
gboolean field_color
Definition dlp_field.c:980
ColRGBA init_color(int id, int numid)
initialize color based id number over total number of elements
Definition initcoord.c:81
angle inversion_3d(cell_info *cell, int mdstep, atom *at, atom *bt, atom *ct, atom *dt)
inversion angle between atom a, b, c and d in 3D
Definition ogl_utils.c:240
angle angle_3d(cell_info *cell, int mdstep, atom *at, atom *bt, atom *ct)
angle between atom a, b and c in 3D
Definition ogl_utils.c:179
distance distance_3d(cell_info *cell, int mdstep, atom *at, atom *bt)
distance between atom a and b in 3D
Definition ogl_utils.c:81
Definition glwin.h:114
double angle
Definition glwin.h:115
gboolean pbc
Definition glwin.h:116
Definition global.h:886
double z
Definition global.h:892
double y
Definition global.h:891
double length
Definition glwin.h:123
double z
Definition glwin.h:126
double y
Definition glwin.h:125
gboolean pbc
Definition glwin.h:127
double x
Definition glwin.h:124
float y
Definition math_3d.h:130
float x
Definition math_3d.h:130
float z
Definition math_3d.h:130
int b
Definition tab-1.c:95
int a
Definition tab-1.c:95