/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: read_dcd_step(FILE *dcd_infile, int &frame, int &natoms, int &reverseEndian) { int charmm = 0 ; int num_fixed = 0 ; int result ; std::vector<float> vector_x(natoms) ; std::vector<float> vector_y(natoms) ; std::vector<float> vector_z(natoms) ; result = read_dcdstep(dcd_infile,natoms,&vector_x[0],&vector_y[0],&vector_z[0],num_fixed,frame,reverseEndian,charmm) ; if(_x().cols() < frame) { std::cout << "resizing array: cols() = " << _x().cols() << " frame = " << frame << std::endl ; resize_array() ; } for(int i = 0 ; i < _natoms() ; ++i) { _x()(i,frame) = vector_x[i] ; _y()(i,frame) = vector_y[i] ; _z()(i,frame) = vector_z[i] ; } _number_of_frames()++ ; return ; }
static int read_next_timestep(void *v, int natoms, molfile_timestep_t *ts) { dcdhandle *dcd; int i, j, rc; float unitcell[6]; unitcell[0] = unitcell[2] = unitcell[5] = 1.0f; unitcell[1] = unitcell[3] = unitcell[4] = 90.0f; dcd = (dcdhandle *)v; /* Check for EOF here; that way all EOF's encountered later must be errors */ if (dcd->setsread == dcd->nsets) return MOLFILE_EOF; dcd->setsread++; if (!ts) { if (dcd->first && dcd->nfixed) { /* We can't just skip it because we need the fixed atom coordinates */ rc = read_dcdstep(dcd->fd, dcd->natoms, dcd->x, dcd->y, dcd->z, unitcell, dcd->nfixed, dcd->first, dcd->freeind, dcd->fixedcoords, dcd->reverse, dcd->charmm); dcd->first = 0; return rc; /* XXX this needs to be updated */ } dcd->first = 0; /* XXX this needs to be changed */ return skip_dcdstep(dcd->fd, dcd->natoms, dcd->nfixed, dcd->charmm); } rc = read_dcdstep(dcd->fd, dcd->natoms, dcd->x, dcd->y, dcd->z, unitcell, dcd->nfixed, dcd->first, dcd->freeind, dcd->fixedcoords, dcd->reverse, dcd->charmm); dcd->first = 0; if (rc < 0) { print_dcderror("read_dcdstep", rc); return MOLFILE_ERROR; } /* copy timestep data from plugin-local buffers to VMD's buffer */ /* XXX * This code is still the root of all evil. Just doing this extra copy * cuts the I/O rate of the DCD reader from 728 MB/sec down to * 394 MB/sec when reading from a ram filesystem. * For a physical disk filesystem, the I/O rate goes from * 187 MB/sec down to 122 MB/sec. Clearly this extra copy has to go. */ { int natoms = dcd->natoms; float *nts = ts->coords; const float *bufx = dcd->x; const float *bufy = dcd->y; const float *bufz = dcd->z; for (i=0, j=0; i<natoms; i++, j+=3) { nts[j ] = bufx[i]; nts[j + 1] = bufy[i]; nts[j + 2] = bufz[i]; } } ts->A = unitcell[0]; ts->B = unitcell[2]; ts->C = unitcell[5]; if (unitcell[1] >= -1.0 && unitcell[1] <= 1.0 && unitcell[3] >= -1.0 && unitcell[3] <= 1.0 && unitcell[4] >= -1.0 && unitcell[4] <= 1.0) { /* This file was generated by CHARMM, or by NAMD > 2.5, with the angle */ /* cosines of the periodic cell angles written to the DCD file. */ /* This formulation improves rounding behavior for orthogonal cells */ /* so that the angles end up at precisely 90 degrees, unlike acos(). */ ts->alpha = 90.0 - asin(unitcell[4]) * 90.0 / M_PI_2; /* cosBC */ ts->beta = 90.0 - asin(unitcell[3]) * 90.0 / M_PI_2; /* cosAC */ ts->gamma = 90.0 - asin(unitcell[1]) * 90.0 / M_PI_2; /* cosAB */ } else { /* This file was likely generated by NAMD 2.5 and the periodic cell */ /* angles are specified in degrees rather than angle cosines. */ ts->alpha = unitcell[4]; /* angle between B and C */ ts->beta = unitcell[3]; /* angle between A and C */ ts->gamma = unitcell[1]; /* angle between A and B */ } return MOLFILE_SUCCESS; }
static PyObject * __read_next_frame(PyObject *self, PyObject *args) { dcdhandle *dcd; PyObject *temp; PyArrayObject *x, *y, *z, *uc; int skip=1; int rc,numskip; float* unitcell; float alpha, beta, gamma; if (!self) { /* we were in fact called as a module function, try to retrieve a matching object from args */ if( !PyArg_ParseTuple(args, "OO!O!O!O!|i", &self, &PyArray_Type, &x, &PyArray_Type, &y, &PyArray_Type, &z, &PyArray_Type, &uc, &skip) ) return NULL; } else { /* we were obviously called as an object method so args should only have the int value. */ if( !PyArg_ParseTuple(args, "O!O!O!O!|i", &PyArray_Type, &x, &PyArray_Type, &y, &PyArray_Type, &z, &PyArray_Type, &uc, &skip) ) return NULL; } if ((temp = PyObject_GetAttrString(self, "_dcd_C_ptr")) == NULL) { // This gives me a New Reference // Raise exception PyErr_SetString(PyExc_AttributeError, "_dcd_C_ptr is not an attribute"); return NULL; } dcd = (dcdhandle*)PyCObject_AsVoidPtr(temp); Py_DECREF(temp); unitcell = (float*) uc->data; unitcell[0] = unitcell[2] = unitcell[5] = 0.0f; unitcell[1] = unitcell[3] = unitcell[4] = 90.0f; /* Check for EOF here; that way all EOF's encountered later must be errors */ if (dcd->setsread == dcd->nsets) { // Is this an exception? PyErr_SetString(PyExc_IOError, "End of file reached for dcd file"); return NULL; //return MOLFILE_EOF; } if (skip > 1) { if (dcd->first && dcd->nfixed) { /* We can't just skip it because we need the fixed atom coordinates */ rc = read_dcdstep(dcd->fd, dcd->natoms, (float*)x->data, (float*)y->data, (float*)z->data, unitcell, dcd->nfixed, dcd->first, dcd->freeind, dcd->fixedcoords, dcd->reverse, dcd->charmm); dcd->first = 0; if (rc < 0) { // return an exception PyErr_SetString(PyExc_IOError, "Error reading first frame from DCD file"); //fprintf(stderr, "read_dcdstep returned %d\n", rc); return NULL; //return MOLFILE_ERROR; } dcd->setsread++; temp = Py_BuildValue("i", dcd->setsread); return temp; //return rc; /* XXX this needs to be updated */ } dcd->first = 0; // Figure out how many steps to skip numskip = skip - (dcd->setsread % skip) - 1; /* XXX this needs to be changed */ rc = skip_dcdstep(dcd->fd, dcd->natoms, dcd->nfixed, dcd->charmm, numskip); if (rc < 0) { // return an exception PyErr_SetString(PyExc_IOError, "Error skipping frame from DCD file"); //fprintf(stderr, "read_dcdstep returned %d\n", rc); return NULL; //return MOLFILE_ERROR; } dcd->setsread+=numskip; } rc = read_dcdstep(dcd->fd, dcd->natoms, (float*)x->data, (float*)y->data, (float*)z->data, unitcell, dcd->nfixed, dcd->first, dcd->freeind, dcd->fixedcoords, dcd->reverse, dcd->charmm); dcd->first = 0; dcd->setsread++; if (rc < 0) { // return an exception PyErr_SetString(PyExc_IOError, "Error reading frame from DCD file"); //fprintf(stderr, "read_dcdstep returned %d\n", rc); return NULL; //return MOLFILE_ERROR; } if (unitcell[1] >= -1.0 && unitcell[1] <= 1.0 && unitcell[3] >= -1.0 && unitcell[3] <= 1.0 && unitcell[4] >= -1.0 && unitcell[4] <= 1.0) { /* This file was generated by Charmm, or by NAMD > 2.5, with the angle */ /* cosines of the periodic cell angles written to the DCD file. */ /* This formulation improves rounding behavior for orthogonal cells */ /* so that the angles end up at precisely 90 degrees, unlike acos(). */ /* (changed in MDAnalysis 0.9.0 to have NAMD ordering of the angles; */ /* see Issue 187) */ alpha = 90.0 - asin(unitcell[4]) * 90.0 / M_PI_2; beta = 90.0 - asin(unitcell[3]) * 90.0 / M_PI_2; gamma = 90.0 - asin(unitcell[1]) * 90.0 / M_PI_2; } else { /* This file was likely generated by NAMD 2.5 and the periodic cell */ /* angles are specified in degrees rather than angle cosines. */ alpha = unitcell[4]; beta = unitcell[3]; gamma = unitcell[1]; } unitcell[4] = alpha; unitcell[3] = beta; unitcell[1] = gamma; // Return the frame read temp = Py_BuildValue("i", dcd->setsread); return temp; }