~ubuntu-branches/ubuntu/raring/gdis/raring-proposed

« back to all changes in this revision

Viewing changes to file_meta.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Leidert (dale)
  • Date: 2009-04-06 17:12:18 UTC
  • mfrom: (3.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090406171218-uizoe126jrq09ytt
Tags: 0.90-1
* New upstream release 0.90.
* Acknowledge NMU (closes: #492994). Thanks to Neil Williams.

* makefile.debian: Upstream doesn't provide a Makefile to edit - so created
  our own.
* debian/compat: Added and set to be 5.
* debian/control: Added Homepage, Vcs* and DM-Upload-Allowed fields.
  (Maintainer): Set to the debichem team with approval by Noèl.
  (Uploaders): Added myself.
  (Build-Depends): Increased debhelper version to 5. Removed glutg3-dev.
  Added dpatch.
  (Standards-Version): Bumped to 3.8.1.
  (Description): Removed homepage. Fixed a typo.
* debian/copyright: Updated, completed and adjusted.
* debian/dirs: Dropped useless file.
* debian/docs: Renamed to debian/gdis.docs.
* debian/menu: Renamed to debian/gdis.menu.
  (section): Fixed accordingly to policy.
* debian/gdis.1: Just some formatting changes.
* debian/gdis.desktop: Added file (with small fixes) provided by Phill Bull
  (LP: #111353).
* debian/gdis.install: Added.
* debian/rules: Cleaned. Installation is now done by dh_install. Make sure,
  the CVS directory is not copied. Added dh_desktop call.
* debian/source.lintian-overrides: makefile.debian is created for Debian but
  lives outside debian/.
* debian/watch: Added.
* debian/README.build: Dropped.
* debian/README.source: Added to be compliant to the policy v3.8.
* debian/patches/Debian_make.dpatch: Added.
  - gdis.h (ELEM_FILE): Moved fix for gdis.elemts path (#399132) to this
    patch.
* debian/patches/00list: Added.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (C) 2003 by Sean David Fleming
 
3
 
 
4
sean@ivec.org
 
5
 
 
6
This program is free software; you can redistribute it and/or
 
7
modify it under the terms of the GNU General Public License
 
8
as published by the Free Software Foundation; either version 2
 
9
of the License, or (at your option) any later version.
 
10
 
 
11
This program is distributed in the hope that it will be useful,
 
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
GNU General Public License for more details.
 
15
 
 
16
You should have received a copy of the GNU General Public License
 
17
along with this program; if not, write to the Free Software
 
18
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
19
 
 
20
The GNU GPL can also be found at http://www.gnu.org
 
21
*/
 
22
 
 
23
#include <stdio.h>
 
24
#include <string.h>
 
25
 
 
26
#include "gdis.h"
 
27
#include "coords.h"
 
28
#include "model.h"
 
29
#include "file.h"
 
30
#include "parse.h"
 
31
#include "select.h"
 
32
#include "interface.h"
 
33
 
 
34
extern struct elem_pak elements[];
 
35
 
 
36
/* meta data for computational chemistry archiving */
 
37
 
 
38
/*****************************************************************/
 
39
/* split a string containing units into it's raw value and units */
 
40
/*****************************************************************/
 
41
void meta_parse_units(gchar **value, gchar **units, gchar *source)
 
42
{
 
43
gchar **buff;
 
44
 
 
45
buff = g_strsplit(source, " ", 2);
 
46
 
 
47
if (*buff+0)
 
48
  *value = g_strdup(*(buff+0));
 
49
else
 
50
  *value = NULL;
 
51
 
 
52
if (*buff+1)
 
53
  *units = g_strdup(*(buff+1));
 
54
else
 
55
  *units = NULL;
 
56
 
 
57
g_strfreev(buff);
 
58
}
 
59
 
 
60
/****************/
 
61
/* file writing */
 
62
/****************/
 
63
gint write_meta(gchar *filename, struct model_pak *model)
 
64
{
 
65
gchar *energy_package=NULL, *energy_value=NULL, *energy_gradient=NULL;
 
66
gchar *energy_method=NULL, *energy_basis=NULL, *energy_functional=NULL;
 
67
gchar *value=NULL, *units=NULL;
 
68
GSList *list;
 
69
FILE *fp;
 
70
 
 
71
/* checks */
 
72
g_return_val_if_fail(model != NULL, 1);
 
73
g_return_val_if_fail(filename != NULL, 2);
 
74
 
 
75
/* open the file */
 
76
fp = fopen(filename,"wt");
 
77
if (!fp)
 
78
  return(3);
 
79
 
 
80
/* fill in the blanks ... */
 
81
/* <key> separator <item1> separator <item 2> ... etc */
 
82
/* separator atm will be '|' */
 
83
 
 
84
/* structural information */
 
85
fprintf(fp, "formula|");
 
86
for (list=model->unique_atom_list ; list ; list=g_slist_next(list))
 
87
  {
 
88
  int code = GPOINTER_TO_INT(list->data);
 
89
  select_clear(model);
 
90
  select_all_elem(code, model);
 
91
  fprintf(fp, "%s %d ", elements[code].symbol, g_slist_length(model->selection));
 
92
  }
 
93
fprintf(fp, "\n");
 
94
fprintf(fp, "molecules|%d\n", g_slist_length(model->moles));
 
95
fprintf(fp, "dimensionality|%d\n", model->periodic);
 
96
switch(model->periodic)
 
97
  {
 
98
  case 3:
 
99
    fprintf(fp, "cell|%f %f %f %f %f %f\n",
 
100
                 model->pbc[0], model->pbc[1], model->pbc[2],
 
101
                 R2D*model->pbc[3], R2D*model->pbc[4], R2D*model->pbc[5]);
 
102
    fprintf(fp, "spacegroup|%s\n", model->sginfo.spacename);
 
103
    break;
 
104
 
 
105
  case 2:
 
106
    fprintf(fp, "cell|%f %f %f \n",
 
107
                 model->pbc[0], model->pbc[1], R2D*model->pbc[5]);
 
108
    break;
 
109
 
 
110
  case 1:
 
111
    fprintf(fp, "cell|%f\n", model->pbc[0]);
 
112
    break;
 
113
  }
 
114
 
 
115
/* energetics information */
 
116
/* only for recognized output types ... input files only have structual meta data stored */
 
117
/* check eligible types for energy etc output */
 
118
/* TODO - include a version number (if available) in package??? */
 
119
energy_value = property_lookup("Energy", model);
 
120
 
 
121
switch(model->id)
 
122
  {
 
123
  case ABINIT_OUT:
 
124
    energy_package = g_strdup("ABINIT");
 
125
    energy_gradient = property_lookup("RMS Gradient", model);
 
126
    break;
 
127
  case CASTEP_OUT:
 
128
    energy_package = g_strdup("CASTEP");
 
129
    energy_gradient = property_lookup("RMS Gradient", model);
 
130
    energy_functional = property_lookup("Functional", model);
 
131
    break;
 
132
  case GAMESS_OUT:
 
133
    energy_package = g_strdup("GAMESS");
 
134
    energy_gradient = property_lookup("RMS Gradient", model);
 
135
    energy_basis = property_lookup("Basis", model);
 
136
    break;
 
137
  case GAUSS_OUT:
 
138
    energy_package = g_strdup("GAUSSIAN");
 
139
    energy_method = property_lookup("Method", model);
 
140
    energy_gradient = property_lookup("RMS Gradient", model);
 
141
    energy_basis = property_lookup("Basis", model);
 
142
    break;
 
143
  case GULPOUT:
 
144
    energy_package = g_strdup("GULP");
 
145
    energy_method = g_strdup("Forcefield");
 
146
    energy_value = property_lookup("Energy", model);
 
147
    energy_gradient = property_lookup("Gnorm", model);
 
148
    break;
 
149
  case MVNOUT:
 
150
    energy_package = g_strdup("MARVIN");
 
151
    energy_method = g_strdup("Forcefield");
 
152
    energy_gradient = property_lookup("Gnorm", model);
 
153
    break;
 
154
  case NWCHEM_OUT:
 
155
    energy_package = g_strdup("NWCHEM");
 
156
    energy_gradient = property_lookup("RMS Gradient", model);
 
157
    break;
 
158
  case SIESTA_OUT:
 
159
    energy_package = g_strdup("SIESTA");
 
160
    energy_gradient = property_lookup("Maximum Gradient", model);
 
161
    energy_functional = property_lookup("Functional", model);
 
162
    break;
 
163
  }
 
164
 
 
165
if (energy_package)
 
166
  {
 
167
  fprintf(fp, "package|%s\n", energy_package);
 
168
  g_free(energy_package);
 
169
  }
 
170
if (energy_method)
 
171
  {
 
172
  fprintf(fp, "method|%s\n", energy_method);
 
173
  g_free(energy_method);
 
174
  }
 
175
if (energy_basis)
 
176
  {
 
177
  fprintf(fp, "basis|%s\n", energy_basis);
 
178
  g_free(energy_basis);
 
179
  }
 
180
if (energy_functional)
 
181
  {
 
182
  fprintf(fp, "functional|%s\n", energy_functional);
 
183
  g_free(energy_functional);
 
184
  }
 
185
 
 
186
if (energy_value)
 
187
  {
 
188
  meta_parse_units(&value, &units, energy_value);
 
189
  if (value)
 
190
    {
 
191
    fprintf(fp, "energy|%s", value);
 
192
    g_free(value);
 
193
    if (units)
 
194
      {
 
195
      fprintf(fp, "|%s", units);
 
196
      g_free(units);
 
197
      }
 
198
    }
 
199
  fprintf(fp, "\n");
 
200
  g_free(energy_value);
 
201
  }
 
202
 
 
203
if (energy_gradient)
 
204
  {
 
205
  meta_parse_units(&value, &units, energy_gradient);
 
206
  if (value)
 
207
    {
 
208
    fprintf(fp, "gradient|%s", value);
 
209
    g_free(value);
 
210
    if (units)
 
211
      {
 
212
      fprintf(fp, "|%s", units);
 
213
      g_free(units);
 
214
      }
 
215
    }
 
216
  fprintf(fp, "\n");
 
217
  g_free(energy_gradient);
 
218
  }
 
219
 
 
220
fclose(fp);
 
221
return(0);
 
222
}
 
223