2 * This file is part of the GROMACS molecular simulation package.
4 * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
5 * Copyright (c) 2001-2013, The GROMACS development team.
6 * Copyright (c) 2013,2014,2015,2017,2019, by the GROMACS development team, led by
7 * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
8 * and including many others, as listed in the AUTHORS file in the
9 * top-level source directory and at http://www.gromacs.org.
11 * GROMACS is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public License
13 * as published by the Free Software Foundation; either version 2.1
14 * of the License, or (at your option) any later version.
16 * GROMACS is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
21 * You should have received a copy of the GNU Lesser General Public
22 * License along with GROMACS; if not, see
23 * http://www.gnu.org/licenses, or write to the Free Software Foundation,
24 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 * If you want to redistribute modifications to GROMACS, please
27 * consider that scientific software is very special. Version
28 * control is crucial - bugs must be traceable. We will be happy to
29 * consider code for inclusion in the official distribution, but
30 * derived work must not be called official GROMACS. Details are found
31 * in the README & COPYING files - if they are missing, get the
32 * official version at http://www.gromacs.org.
34 * To help us fund GROMACS development, we humbly ask that you cite
35 * the research papers on the package. Check out http://www.gromacs.org.
43 #include "gromacs/fileio/writeps.h"
44 #include "gromacs/utility/smalloc.h"
55 static void ps_draw_atom(t_psdata* ps, int ai, iv2 vec2[], char** atomnm[])
61 ps_rgb(ps, Type2RGB(*atomnm[ai]));
62 ps_line(ps, xi - MSIZE, yi, xi + MSIZE + 1, yi);
63 ps_line(ps, xi, yi - MSIZE, xi, yi + MSIZE + 1);
66 /* Global variables */
67 static rvec gl_fbox, gl_hbox, gl_mhbox;
69 static void init_pbc(matrix box)
73 for (i = 0; (i < DIM); i++)
75 gl_fbox[i] = box[i][i];
76 gl_hbox[i] = gl_fbox[i] * 0.5;
77 gl_mhbox[i] = -gl_hbox[i];
81 static bool local_pbc_dx(rvec x1, rvec x2)
86 for (i = 0; (i < DIM); i++)
93 else if (dx <= gl_mhbox[i])
101 static void ps_draw_bond(t_psdata* ps, int ai, int aj, iv2 vec2[], rvec x[], char** atomnm[])
107 if (local_pbc_dx(x[ai], x[aj]))
121 ps_rgb(ps, Type2RGB(ic));
122 ps_line(ps, xi, yi, xm, ym);
123 ps_rgb(ps, Type2RGB(jc));
124 ps_line(ps, xm, ym, xj, yj);
128 ps_rgb(ps, Type2RGB(ic));
129 ps_line(ps, xi, yi, xj, yj);
134 static void ps_draw_objects(t_psdata* ps, int nobj, t_object objs[], iv2 vec2[], rvec x[], char** atomnm[], bool bShowHydro)
139 for (i = 0; (i < nobj); i++)
144 case eOSingle: ps_draw_atom(ps, obj->ai, vec2, atomnm); break;
145 case eOBond: ps_draw_bond(ps, obj->ai, obj->aj, vec2, x, atomnm); break;
149 ps_draw_bond(ps, obj->ai, obj->aj, vec2, x, atomnm);
157 static void v4_to_iv2(vec4 x4, iv2 v2, int x0, int y0, real sx, real sy)
161 inv_z = 1.0 / x4[ZZ];
162 v2[XX] = x0 + sx * x4[XX] * inv_z;
163 v2[YY] = y0 - sy * x4[YY] * inv_z;
166 static void draw_box(t_psdata* ps, t_3dview* view, matrix box, int x0, int y0, real sx, real sy)
168 int ivec[8][4] = { { 0, 0, 0, 1 }, { 1, 0, 0, 1 }, { 1, 1, 0, 1 }, { 0, 1, 0, 1 },
169 { 0, 0, 1, 1 }, { 1, 0, 1, 1 }, { 1, 1, 1, 1 }, { 0, 1, 1, 1 } };
170 int bonds[12][2] = { { 0, 1 }, { 1, 2 }, { 2, 3 }, { 3, 0 }, { 4, 5 }, { 5, 6 },
171 { 6, 7 }, { 7, 4 }, { 0, 4 }, { 1, 5 }, { 2, 6 }, { 3, 7 } };
177 for (i = 0; (i < 8); i++)
179 for (j = 0; (j < DIM); j++)
181 corner[i][j] = ivec[i][j] * box[j][j];
183 gmx_mat4_transform_point(view->proj, corner[i], x4);
184 v4_to_iv2(x4, vec2[i], x0, y0, sx, sy);
186 ps_color(ps, 0, 0, 0.5);
187 for (i = 0; (i < 12); i++)
189 ps_line(ps, vec2[bonds[i][0]][XX], vec2[bonds[i][0]][YY], vec2[bonds[i][1]][XX],
190 vec2[bonds[i][1]][YY]);
194 void ps_draw_mol(t_psdata* ps, t_manager* man)
216 y0 = win->height / 2;
217 sx = win->width / 2 * view->sc_x;
218 sy = win->height / 2 * view->sc_y;
222 for (i = 0; (i < man->natom); i++)
226 gmx_mat4_transform_point(view->proj, man->x[i], x4);
228 v4_to_iv2(x4, vec2[i], x0, y0, sx, sy);
233 z_fill(man, man->zz);
236 XClearWindow(x11->disp,win->self); */
238 if (mw->boxtype != esbNone)
240 draw_box(ps, view, man->box, x0, y0, sx, sy);
243 /* Should sort on Z-Coordinates here! */
244 nvis = filter_vis(man);
245 if (nvis && man->bSort)
247 std::qsort(man->obj, nvis, sizeof(man->obj[0]), compare_obj);
250 /* Draw the objects */
251 ps_draw_objects(ps, nvis, man->obj, man->ix, man->x, man->top.atoms.atomname, mw->bShowHydrogen);
253 /* Draw the labels */
254 ps_color(ps, 0, 0, 0);
255 for (i = 0; (i < man->natom); i++)
257 if (man->bLabel[i] && man->bVis[i])
259 ps_text(ps, vec2[i][XX] + 2, vec2[i][YY] - 2, man->szLab[i]);