xyz2rgb
|
1crn.gif,
PDB3D.zip,
README.jkl,
_index.html,
babel-mod.tar.gz,
c50_pent.zip,
c50lib,
c50lib.tar.gz,
cc-prize.html,
cones.jpg,
crambin.mpg,
deter-response.gz,
globus-tube.gif,
globus-xyzs,
globus-xyzs.tar.gz,
lisp2c.lsp,
lucier-email.gz,
m3dxyz.c,
make-cones,
ncad021,
ncad021.tar.gz,
ncad021.zip,
ncad022,
ncad022.tar.gz,
ncad022.zip,
ncad023,
ncad023.tar.gz,
ncad023a,
ncad023a.tar.gz,
ncad023b,
ncad023b.tar.gz,
pdb2ps.c,
tv,
verl-fun.zip,
verlet-fun,
verlet-fun.tar.gz,
x-app,
x-app.tar.gz,
xyz2rgb,
xyz2rgb.c,
xyz2rgb.html,
xyz2rgb.tar.gz,
|
|
|
/*
* m3dxyz.c - C program, translate M3D files to XYZ files
* Copyright (C) 1996 Will Ware
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You can get a copy of the GNU General Public License by writing
* to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge,
* MA 02139, USA. It's also in a million places on the net.
*
* I can be reached via email at .
*/
#include
unsigned long initial_num_atoms; /* before discarding EPs */
unsigned long real_num_atoms; /* after discarding EPs */
const char *usage_string =
"\n"
"Example usage: m3dxyz glop.m3d glop.xyz\n"
" or: m3dxyz glop.m3d > glop.xyz\n"
"\n"
"Converts Molecular Arts M3D file to an XYZ file, readable by Babel or\n"
"RasMol. This program discards M3D information on lone electron pairs\n"
"because Babel doesn't know how to handle them.\n"
"\n";
void usage(void)
{
printf(usage_string);
exit(1);
}
void do_pass(char *filename, FILE *outf, int pass)
{
FILE *inf;
char line[200];
char name[10];
float x, y, z;
int dummy1, dummy2;
unsigned long i;
inf = fopen(filename, "r");
if (inf == NULL)
{
fprintf(stderr, "m3dxyz can't open input file %s\n", filename);
exit(1);
}
fgets(line, 200, inf);
fgets(line, 200, inf);
if (pass == 1)
{
sscanf(line, " %ld", &initial_num_atoms);
real_num_atoms = initial_num_atoms;
}
if (pass == 2)
fprintf(outf, "%ld\nGlop\n", real_num_atoms);
for (i = 0; i < initial_num_atoms; i++)
{
fgets(line, 200, inf);
sscanf(line, "%d %s %d %f %f %f",
&dummy1, name, &dummy2, &x, &y, &z);
/* discard electron pairs, Babel doesn't understand them */
if (strcmp(name, "ep") == 0)
{
if (pass == 1)
real_num_atoms--;
}
else if (pass == 2)
fprintf(outf, "%s %f %f %f\n", name, x, y, z);
}
fclose(inf);
}
void main(int argc, char *argv[])
{
FILE *outf;
if (argc < 2)
usage();
if (argc > 2)
{
outf = fopen(argv[2], "w");
if (outf == NULL)
{
fprintf(stderr, "m3dxyz can't open output file %s\n", argv[2]);
exit(1);
}
}
else
outf = stdout;
do_pass(argv[1], outf, 1);
do_pass(argv[1], outf, 2);
}
|