void XMLArchive::WriteField(const Residue &res) { /* write a RESIDUE field */ tags.push_back("Residue"); calc_indent(); char secstr = res.secstr(); // this fixes a wierd bug - if these happen to be 0 - disaster! if (!isalpha(secstr)) { secstr = 'U'; } if (!isalpha(res.name1())) { secstr = 'X'; } f = format("%s<Residue name=\"%s\" type=\"%s\" chain=\"%d\" secstr=\"%c\" confomer=\"%d\" flags=\"%d\" linkage_type=\"%d\" name1=\"%c\" seqpos=\"%d\" >\n", indent, res.name().c_str(), res.type().c_str(), (int)res.chain_id(), secstr, (int)res.confomer(), (int)res.flags(), (int)res.linkage_type(), res.name1(), res.seqpos()); Write(f); inTag++; for (int i = 0; i < res.atomCount(); i++) { WriteField(res.atom(i)); } EndTag(); }
void RibbonEngine::updateChains(PainterDevice *pd) { if (!isEnabled()) return; m_chains.clear(); QList<Primitive *> list; list = primitives().subList(Primitive::ResidueType); unsigned int currentChain = 0; QVector<Vector3d> pts; // Get a list of residues for the molecule const Molecule *molecule = pd->molecule(); foreach(Primitive *p, list) { Residue *r = static_cast<Residue *>(p); if(r->name() =="HOH") { continue; } if(r->chainNumber() != currentChain) { // this residue is on a new chain if(pts.size() > 0) m_chains.push_back(pts); currentChain = r->chainNumber(); pts.clear(); } foreach (unsigned long atom, r->atoms()) { // should be CA QString atomId = r->atomId(atom); atomId = atomId.trimmed(); if (atomId == "CA") { pts.push_back(*molecule->atomById(atom)->pos()); } else if (atomId == "N" && m_useNitrogens == 2) { pts.push_back(*molecule->atomById(atom)->pos()); } } // end atoms in residue } // end primitive list (i.e., all residues)
Residue *SymmResidue(const Residue *Model, CMapHeaderBase *mh, float center[3], float r, int color) { /* set unity to true if operator = x,y,z to avoid looking at 0,0,0 position */ const Residue *model; Residue *res = NULL, *newres, *Res = NULL; char label[MAXNAME]; int nlabel; int nadd = 0; int i, j, k, n = 0; float minxyz[3], maxxyz[3]; float sminxyz[3], smaxxyz[3]; float fx, fy, fz; int ix, iy, iz; float x1, y1, z1; float cx1, cy1, cz1, cx2, cy2, cz2; float pos[3]; float cx, cy, cz, dx, dy, dz; float symmat[3][4]; float ctof[3][3]; float ftoc[3][3]; for (j = 0; j < 3; j++) { for (k = 0; k < 3; k++) { ctof[j][k] = mh->ctof[j][k]; ftoc[j][k] = mh->ftoc[j][k]; } } minxyz[0] = 9999.0; minxyz[1] = 9999.0; minxyz[2] = 9999.0; maxxyz[0] = -9999.0; maxxyz[1] = -9999.0; maxxyz[2] = -9999.0; cx = center[X]; cy = center[Y]; cz = center[Z]; cx1 = center[X]-r; cy1 = center[Y]-r; cz1 = center[Z]-r; cx2 = center[X]+r; cy2 = center[Y]+r; cz2 = center[Z]+r; transform(ctof, &cx, &cy, &cz); transform(ctof, &cx1, &cy1, &cz1); transform(ctof, &cx2, &cy2, &cz2); for (int symmop = 0; symmop < mh->nsym; symmop++) { /* put res at end of list */ sprintf(label, "#%d", symmop); nlabel = strlen(label); for (j = 0; j < 3; j++) { for (k = 0; k < 4; k++) { symmat[j][k] = mh->symops[j][k][symmop]; } } /* find min max of model in fractional */ model = Model; while (model != NULL) { for (i = 0; i < model->atomCount(); i++) { if (model->atom(i)->x() < minxyz[X]) { minxyz[X] = model->atom(i)->x(); } if (model->atom(i)->y() < minxyz[Y]) { minxyz[Y] = model->atom(i)->y(); } if (model->atom(i)->z() < minxyz[Z]) { minxyz[Z] = model->atom(i)->z(); } if (model->atom(i)->x() > maxxyz[X]) { maxxyz[X] = model->atom(i)->x(); } if (model->atom(i)->y() > maxxyz[Y]) { maxxyz[Y] = model->atom(i)->y(); } if (model->atom(i)->z() > maxxyz[Z]) { maxxyz[Z] = model->atom(i)->z(); } } model = model->next(); } /* convert to fractional */ transform(ctof, &minxyz[X], &minxyz[Y], &minxyz[Z]); transform(ctof, &maxxyz[X], &maxxyz[Y], &maxxyz[Z]); /* find symmetry min max */ symm(minxyz[X], minxyz[Y], minxyz[Z], &sminxyz[X], &sminxyz[Y], &sminxyz[Z], symmat); symm(maxxyz[X], maxxyz[Y], maxxyz[Z], &smaxxyz[X], &smaxxyz[Y], &smaxxyz[Z], symmat); for (i = 0; i < 3; i++) { if (sminxyz[i] > smaxxyz[i]) { float t = sminxyz[i]; sminxyz[i] = smaxxyz[i]; smaxxyz[i] = t; } } /* look at unit cells -1 to +1 around minmax */ dx = cx - (sminxyz[X]+smaxxyz[X])/2.0 ; dy = cy - (sminxyz[Y]+smaxxyz[Y])/2.0 ; dz = cz - (sminxyz[Z]+smaxxyz[Z])/2.0 ; for (ix = -1; ix <= 1; ix += 1) { for (iy = -1; iy <= 1; iy += 1) { for (iz = -1; iz <= 1; iz += 1) { /* if (symmop==0 && ix==0 && iy==0 && iz==0) continue; */ fx = ROUND(dx + ix); fy = ROUND(dy + iy); fz = ROUND(dz + iz); n++; model = Model; while (model != NULL) { /* look for any atom to be within radius- if so copy entire residue and move on */ for (i = 0; i < model->atomCount(); i++) { x1 = model->atom(i)->x(); y1 = model->atom(i)->y(); z1 = model->atom(i)->z(); transform(ctof, &x1, &y1, &z1); symm(x1, y1, z1, &x1, &y1, &z1, symmat); x1 += fx; y1 += fy; z1 += fz; transform(ftoc, &x1, &y1, &z1); pos[X] = x1; pos[Y] = y1; pos[Z] = z1; if (outside_sphere(pos, r, center)) { continue; } if (symmop == 0 && x1 < model->atom(i)->x()+.1 && x1 > model->atom(i)->x()-.1 && y1 < model->atom(i)->y()+.1 && y1 > model->atom(i)->y()-.1 && z1 < model->atom(i)->z()+.1 && z1 > model->atom(i)->z()-.1) { continue; } newres = new Residue(*model); if (Res == NULL) { Res = res = newres; } else { res = res->insertResidue(newres); } /* now transform the atoms */ if ((int)strlen(res->name().c_str()) < MAXNAME-nlabel) { res->setName(res->name() + std::string(label)); } for (j = 0; j < res->atomCount(); j++) { x1 = res->atom(j)->x(); y1 = res->atom(j)->y(); z1 = res->atom(j)->z(); transform(ctof, &x1, &y1, &z1); symm(x1, y1, z1, &x1, &y1, &z1, symmat); x1 += fx; y1 += fy; z1 += fz; transform(ftoc, &x1, &y1, &z1); res->atom(j)->setPosition(x1, y1, z1); res->atom(j)->setColor(color); res->atom(j)->setSymmop(symmop); res->atom(j)->addType(AtomType::SYMMATOM); /* save fx,fy,fz for later */ res->atom(j)->resetDelta(); res->atom(j)->addDelta(fx, fy, fz); nadd++; } break; } model = model->next(); // if(wait.CheckForAbort()) model=NULL; } } } } } Logger::log("Built %d symmatoms", nadd); return (Res); }