Example #1
0
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();
}
Example #2
0
void Displaylist::ProbeSurface(Residue *reslist, MIAtomList a)
{
    vector<SURFDOT>::iterator p;
    MIAtom_iter pa;
    Residue *res = reslist;
    float r1, dx, dy, dz, dr;
    int i;
    MIAtomList b;
    MIAtom *atom;

    while (res != NULL)
    {
        for (i = 0; i < res->atomCount(); i++)
        {
            atom = res->atom(i);
            for (pa = a.begin(); pa != a.end(); pa++)
            {
                if (atom == *pa)
                {
                    continue;
                }
            }
            r1 = atom->getRadius();
            for (pa = a.begin(); pa != a.end(); pa++)
            {
                if (AtomDist(**pa, *atom) < (r1 + (*pa)->getRadius()))
                {
                    b.push_back(atom);
                    break;
                }
            }
        }
        res = res->next();
    }
    for (p = CurrentDots.begin(); p != CurrentDots.end(); p++)
    {
        dr = 0.0;
        for (pa = b.begin(); pa != b.end(); pa++)
        {
            r1 = (*pa)->getRadius();
            r1 = r1*r1;
            dx = (*pa)->x() - (*p).x;
            dx = dx*dx;
            if (dx < r1)
            {
                dy = (*pa)->y() - (*p).y;
                dy = dy*dy;
                if (dx+dy < r1)
                {
                    dz = (*pa)->z() - (*p).z;
                    dz = dz*dz;
                    dr = (dx+dy+dz*dz)-r1;
                }
            }
        }
        if (dr < -0.4)
        {
            (*p).color = Colors::WHITE;
            if (dr < -1.2)
            {
                (*p).color = Colors::PINK;
                if (dr < -2.4)
                {
                    (*p).color = Colors::RED;
                }
            }
        }
        else
        {
            (*p).color = -abs((*p).color);
        }
    }
}
Example #3
0
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);
}
Example #4
0
static void AddAnnotations(Molecule *model)
{
    if (model == NULL)
    {
        return;
    }

    std::map<Residue*, std::string> annotations;
    std::string err_type;
    std::vector<std::string> headers = *model->GetFileHead();

    for (size_t i = 0; i < headers.size(); ++i)
    {
        // get class of error
        if (strncmp("REMARK 500 SUBTOPIC:", headers[i].c_str(), 20)==0
            || strncmp("REMARK 501 SUBTOPIC:", headers[i].c_str(), 20)==0)
        {
            err_type = ""; // clear type on new subtopic
            if (headers[i].size() > 22)
            {
                if (headers[i].find("BOND LENGTHS", 21)!=std::string::npos)
                {
                    err_type = std::string("Geometry (bond length)");
                }
                else if (headers[i].find("BOND ANGLES", 21)!=std::string::npos)
                {
                    err_type = std::string("Geometry (bond angle)");
                }
                else if (headers[i].find("CHIRAL", 21)!=std::string::npos)
                {
                    err_type = std::string("Geometry (chiral)");
                }
                else if (headers[i].find("NON-CIS", 21)!=std::string::npos)
                {
                    err_type = std::string("Omega");
                }
                else if (headers[i].find("CLOSE CONTACTS", 21)!=std::string::npos)
                {
                    err_type = std::string("Van der Waals");
                }
                else if (headers[i].find("TORSION ANGLES", 21)!=std::string::npos)
                {
                    err_type = std::string("Phi-psi");
                }
                else if (headers[i].find("ELECTRON DENSITY", 21)!=std::string::npos)
                {
                    err_type = std::string("Density");
                }
                else if (headers[i].find("ELECTRON DENSITY", 21)!=std::string::npos)
                {
                    err_type = std::string("Density");
                }
                else if (headers[i].find("ROTAMER", 21)!=std::string::npos)
                {
                    err_type = std::string("Rotamer chi-1");
                }
                else if (headers[i].find("CIS PEPTIDE", 21)!=std::string::npos)
                {
                    err_type = std::string("Cis peptide");
                }
            }
        }

        int dum;
        char rname[4], rnum[6];
        char chain;
        if (err_type != ""
            && (strncmp("REMARK 500   ", headers[i].c_str(), 13)==0
                || strncmp("REMARK 501   ", headers[i].c_str(), 13)==0))
        {
            if ((sscanf(headers[i].c_str(),
                        "REMARK 500   %d %s %c %s", &dum, rname, &chain, rnum)==4)
                || (sscanf(headers[i].c_str(),
                           "REMARK 501   %d %s %c %s", &dum, rname, &chain, rnum)==4))
            {
                Residue *res = residue_from_name(model->residuesBegin(), rnum, chain);
                if (res != NULL)
                {
                    std::string tmp = annotations[res];
                    if (tmp.size()==0)
                        tmp = ::format("Error in %c %s %s: %s", chain, rnum, rname, err_type.c_str());
                    else
                        tmp = ::format("%s, %s", tmp.c_str(), err_type.c_str());
                    annotations[res] = tmp;
                }
            }
        }
    }

    bool hidden = !QSettings().value("DisplayView/autoShowError", true).toBool();


    for (std::map<Residue*, std::string>::iterator i = annotations.begin(); i!=annotations.end(); ++i)
    {
        Residue *res = i->first;
        std::string &text = i->second;
        MIAtom *atom = atom_from_name("CA", *res);
        if (atom == NULL && res->atomCount() > 0)
        {
            atom = res->atom(0);
        }
        if (atom != NULL)
        {
            Annotation *annotation = new Annotation(text.c_str(), atom->x(), atom->y(), atom->z());
            annotation->setHidden(hidden);
            model->addAnnotation(annotation);
        }
    }
}