static int write_timestep(void *v, const molfile_timestep_t *ts) { dcdhandle *dcd = (dcdhandle *)v; int i, rc, curstep; float *pos = ts->coords; double unitcell[6]; unitcell[0] = unitcell[2] = unitcell[5] = 1.0f; unitcell[1] = unitcell[3] = unitcell[4] = 90.0f; /* copy atom coords into separate X/Y/Z arrays for writing */ for (i=0; i<dcd->natoms; i++) { dcd->x[i] = *(pos++); dcd->y[i] = *(pos++); dcd->z[i] = *(pos++); } dcd->nsets++; curstep = dcd->istart + dcd->nsets * dcd->nsavc; unitcell[0] = ts->A; unitcell[2] = ts->B; unitcell[5] = ts->C; unitcell[1] = sin((M_PI_2 / 90.0) * (90.0 - ts->gamma)); /* cosAB */ unitcell[3] = sin((M_PI_2 / 90.0) * (90.0 - ts->beta)); /* cosAC */ unitcell[4] = sin((M_PI_2 / 90.0) * (90.0 - ts->alpha)); /* cosBC */ rc = write_dcdstep(dcd->fd, dcd->nsets, curstep, dcd->natoms, dcd->x, dcd->y, dcd->z, dcd->with_unitcell ? unitcell : NULL, dcd->charmm); if (rc < 0) { print_dcderror("write_dcdstep", rc); return MOLFILE_ERROR; } return MOLFILE_SUCCESS; }
/// /// @par Detailed description /// ... /// @param [in, out] (param1) ... /// @return ... /// @note ... void sasio::Files:: write_dcd_step(FILE *outfile, int &frame, int &step) { int step_result = 0 ; step_result = write_dcdstep(outfile,_natoms(),&_x()(0,frame),&_y()(0,frame),&_z()(0,frame),step+1) ; return ; }
static PyObject * __write_next_frame(PyObject *self, PyObject *args) { dcdhandle *dcd; PyObject *temp; PyArrayObject *x, *y, *z, *uc; int rc, curstep; float* uc_array; double unitcell[6]; 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!", &self, &PyArray_Type, &x, &PyArray_Type, &y, &PyArray_Type, &z, &PyArray_Type, &uc) ) 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!", &PyArray_Type, &x, &PyArray_Type, &y, &PyArray_Type, &z, &PyArray_Type, &uc) ) 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); dcd->nsets++; curstep = dcd->istart + dcd->nsets * dcd->nsavc; uc_array = (float*) uc->data; unitcell[0] = uc_array[0]; /* A */ unitcell[2] = uc_array[2]; /* B */ unitcell[5] = uc_array[5]; /* C */ /* write angle cosines with NAMD ordering [orbeckst] */ /* (changed in MDAnalysis 0.9.0) */ unitcell[4] = sin((M_PI_2 / 90.0 ) * (90.0 - uc_array[4])); /* cos(alpha) */ unitcell[3] = sin((M_PI_2 / 90.0 ) * (90.0 - uc_array[3])); /* cos(beta) */ unitcell[1] = sin((M_PI_2 / 90.0 ) * (90.0 - uc_array[1])); /* cos(gamma) */ if ((rc = write_dcdstep(dcd->fd, dcd->nsets, curstep, dcd->natoms, (float*)x->data, (float*)y->data, (float*)z->data, dcd->with_unitcell ? unitcell: NULL, dcd->charmm)) < 0) { PyErr_SetString(PyExc_IOError, "Could not write timestep to dcd file"); return NULL; } Py_INCREF(Py_None); return Py_None; }