Jake Isaacs wrote:
>
> What is the best way to covert a trajectory into a series of pdb files? If
> more than one program is required, does anyone have a handy script I could
> modify for my purposes?
There are probably better tools for this, but below is some C code that will get the job done in one step. It may need to be tweaked if your
trajectory has box info in it. To use the prog, you need a pdb file of your system (created with ambpdb) and the trajectory file.
--
Jarrod A. Smith
Research Asst. Professor, Biochemistry
Asst. Director, Center for Structural Biology
Computation and Molecular Graphics
Vanderbilt University
jsmith_at_structbio.vanderbilt.edu
#include <stdio.h>
#define USAGE "usage: %s pdb_file trajectory_file\n", argv[ 0 ]
#define ERROR -1
#define SUCCESS 0
#define MAX_ATOMS 50000
#define RNAME_SIZE 4
#define ANAME_SIZE 5
typedef struct{
int rnum, anum;
char rname[RNAME_SIZE], aname[ANAME_SIZE];
float coords[3];
}ATOM;
ATOM atom[MAX_ATOMS];
char line[100];
main(argc, argv)
int argc;
char *argv[];
{
int n_atoms, anum, frame=0, c;
char fname[256];
float f;
FILE *pdbFile, *trajFile;
if (argc < 3) {
fprintf( stderr, USAGE );
exit (ERROR);
}
if ( (pdbFile = fopen( argv[ 1 ], "r")) == NULL ) {
fprintf( stderr, "FATAL: Can't open pdb file %s\n", argv[ 1 ] );
exit (ERROR);
}else{
n_atoms=make_atom_table( pdbFile );
fprintf( stderr, "Found %d atoms in %s. Using this as framesize\n", argv[1]);
}
if ( (trajFile = fopen( argv[ 2 ], "r")) == NULL ) {
fprintf( stderr, "FATAL: Can't open trajectory file %s\n", argv[ 2 ] );
exit (ERROR);
}
fgets( line, sizeof(line), trajFile );
fprintf(stderr, "\n");
while( fscanf( trajFile, "%f", &atom[0].coords[0] ) == 1 ){
frame++;
sprintf( fname, "frame%03d.pdb", frame );
fprintf( stderr, "Extracting frame %d to file %s...\n", frame, fname);
fscanf( trajFile, "%f", &atom[0].coords[1] );
fscanf( trajFile, "%f", &atom[0].coords[2] );
for ( anum = 1; anum < n_atoms; anum++ ){
for ( c = 0; c <= 2; c++ ) fscanf( trajFile, "%f", &atom[anum].coords[c] );
}
writepdb(n_atoms, fname);
}
fclose( trajFile );
exit( SUCCESS );
}
make_atom_table( pdb )
FILE *pdb;
{
int nat;
for ( nat=0; (fgets(line, sizeof(line), pdb)) && (nat < MAX_ATOMS); nat++ ){
if ( (strncmp( "ATOM", line, 4 ) == 0) || (strncmp( "HETATM", line, 6 ) == 0) ){
sscanf(&line[ 6 ], "%d %s %s %d", &atom[ nat ].anum, atom[ nat ].aname,
atom[ nat ].rname, &atom[ nat ].rnum);
}else nat--;
}
fclose( pdb );
return(nat);
}
writepdb( n_atoms, fname )
int n_atoms;
char *fname;
{
int anum;
FILE *pdbout;
if ( (pdbout = fopen( fname, "w")) == NULL ) {
fprintf( stderr, "FATAL: Can't open pdb file %s\n for writing", fname );
exit (ERROR);
}
for ( anum=0; anum < n_atoms; anum++ ){
fprintf( pdbout, "ATOM %6d %-4s %3s %5d %8.3f%8.3f%8.3f\n",
atom[anum].anum, atom[anum].aname, atom[anum].rname, atom[anum].rnum,
atom[anum].coords[0], atom[anum].coords[1], atom[anum].coords[2] );
}
return( SUCCESS );
}
Received on Mon Apr 02 2001 - 15:39:15 PDT