Exemplo n.º 1
0
void InitBSPLog(Int4 randseed,CharPtr sequence,Int4 tstruc)
{
	CharPtr decsequence;
	static Char pcUname[PATH_MAX]="";
	Char timedate[25];
#ifdef OS_UNIX
    struct utsname utsbuf;
#endif

    bspTempLog=BSNew(0);
    /* compute log file name */
	if (generation==0)
	    sprintf(LogOutName,"%sfold_%ld_%s_%ld_%s",CFG_local_datafilepath,(long)experiment,handle,(long)tstruc,fnamtrj);
	else
	    sprintf(LogOutName,"%sfold_%ld_%s_%ld_%s_%s_%d",CFG_local_datafilepath,(long)experiment,handle,(long)tstruc,handle,fnamtrj,generation);
    BSprintf(bspTempLog,"\nFoldtraj v%s log report",FOLDTRAJ_VERSION);
    BSprintf(bspTempLog,"\nTrajectory File: %s%s_%d",CFG_local_datafilepath,fnamtrj,generation);
    BSprintf(bspTempLog,"\tStructure File Base Name: %s_%s_%d",handle,fnamtrj,generation);
    BSprintf(bspTempLog,"\tRandom Seed: %ld\t# Generated: %ld\tStart Numbering at: %ld",randseed,STRUCS_PER_RUN,1);
    BSprintf(bspTempLog,"\tCompared to Native Structure: 1CDZ");

    decsequence=DecodeSequence(sequence,EXTAA_PARENT);
    BSprintf(bspTempLog,"\nSequence: %s",decsequence);
    decsequence=MemFree(decsequence);
    BSprintf(bspTempLog,"\nFolding Conditions:\t%ldx%ld Trajectory Distributions\t%s Random Walk\tAverage Timeout: %ld\tBackbone Error Tolerance: %4.2f\tBackbone Precision: %6.4f\tBackbone Atom Bounciness: %5.2f%%\tSidechain Atom Bounciness: %5.2f %%\tHydrogen Bumpchecking: %s\t# Rotamer Tries: %d/chi angle\tMarkov Scale Factor: %4.2f",
            TRAJDIV,TRAJDIV,WALKTYPE==WALK_CA?"C-Alpha":"Phi-Psi",TIMEOUT,BACKBONE_ERROR_TOLERANCE,
            BACKBONE_PRECISION,ATOM_BOUNCINESS_BB*100.0,ATOM_BOUNCINESS_SC*100.0,
            BUMPCHECK_HYDROGEN?"On":"Off",NUM_ROT_TRIES,MARKOV_SCALE_FACTOR);
    if (WALKTYPE!=WALK_CA && MARKOV_SCALE_FACTOR>0.0)
        ErrPostEx(SEV_ERROR,2,2,"Markov Scale Factor should be zero for non-Ca walk -- ignored");
    if (TRAJTYPE!=TRAJ_NA) {
        BSprintf(bspTempLog,"\tTrajectory Distribution: ");
        switch (TRAJTYPE) {
            case TRAJ_UNIFORM:
                BSprintf(bspTempLog,"Uniform");
                break;
            case TRAJ_STANDARD:
                BSprintf(bspTempLog,"Amino-Acid Based");
                break;
            case TRAJ_SSTRU:
                BSprintf(bspTempLog,"1-State Secondary Structure Prediction");
                break;
            case TRAJ_GOR:
                BSprintf(bspTempLog,"3-State Secondary Structure Prediction");
                break;
            default:
                BSprintf(bspTempLog,"Unknown");
        }
    }
    if (StringCmp(CONSTRAINT_FILE,""))
            BSprintf(bspTempLog,"\tConstraint file: %s",CONSTRAINT_FILE);
    BSprintf(bspTempLog,"\nSystem Information: ");
	
	if (StringLen(pcUname)==0) {
	    StringCpy(pcUname,"Not Available\n");
#ifdef OS_UNIX
	    /* use uname to get sysinfo */
		if (uname(&utsbuf)>=0) {
	        sprintf(pcUname,"%s %s %s %s %s\n",utsbuf.sysname,utsbuf.nodename,utsbuf.release,utsbuf.version,utsbuf.machine);
		}
#else
#ifdef OS_MSWIN
	    /* assume ver is available */
		if (GetMSWinVerInfo(pcUname)!=ERR_SUCCESS) {
            StringCpy(pcUname,"Not Available\n");
	
	    }       
#endif
#endif
	}
	BSWrite(bspTempLog,pcUname,StringLen(pcUname));
    DayTimeStr(timedate,TRUE,TRUE);
    BSprintf(bspTempLog,"Job started: %s\n",timedate);
    BSprintf(bspTempLog,"\nStructure\tTime(s)\tTries\tBad Backbone Tries\tCrashes\tDistant Constraint Tries (# Violations)\tChain Length\tRadius of Gyration(A)\tHydrophobics Radius of Gyration(A)\tEnd-to-end Distance(A)\tRn\tCn");
    BSprintf(bspTempLog,"\tSurface Accessibility (A^2)\tExposed Hydrophobics (A^2)");
    BSprintf(bspTempLog,"\t# Helical Residues (DSSP)\t# Extended Residues (DSSP)");
    BSprintf(bspTempLog,"\t# Extended Residues (CA-CA dist.)");
    BSprintf(bspTempLog,"\tRMSD from Native(A)");
    BSprintf(bspTempLog,"\tZhang Potential(Exclusive Window Size %d)\tBryant-Lawrence Potential(Exclusive Window Size %d)\tCrease Energy\n",ZHANG_WINDOWSIZE,BRYANT_WINDOWSIZE);
}
Exemplo n.º 2
0
static SECStatus DecodeItem(void* dest,
                     const SEC_ASN1Template* templateEntry,
                     SECItem* src, PLArenaPool* arena, PRBool checkTag)
{
    SECStatus rv = SECSuccess;
    SECItem temp;
    SECItem mark;
    PRBool pop = PR_FALSE;
    PRBool decode = PR_TRUE;
    PRBool save = PR_FALSE;
    unsigned long kind;
    PRBool match = PR_TRUE;
    PRBool optional = PR_FALSE;

    PR_ASSERT(src && dest && templateEntry && arena);
#if 0
    if (!src || !dest || !templateEntry || !arena)
    {
        PORT_SetError(SEC_ERROR_INVALID_ARGS);
        rv = SECFailure;
    }
#endif

    if (SECSuccess == rv)
    {
        /* do the template validation */
        kind = templateEntry->kind;
        optional = (0 != (kind & SEC_ASN1_OPTIONAL));
        if (!kind)
        {
            PORT_SetError(SEC_ERROR_BAD_TEMPLATE);
            rv = SECFailure;
        }
    }

    if (SECSuccess == rv)
    {
#ifdef DEBUG
        if (kind & SEC_ASN1_DEBUG_BREAK)
        {
            /* when debugging the decoder or a template that fails to
            decode, put SEC_ASN1_DEBUG in the component that gives you
            trouble. The decoder will then get to this block and assert.
            If you want to debug the rest of the code, you can set a
            breakpoint and set dontassert to PR_TRUE, which will let
            you skip over the assert and continue the debugging session
            past it. */
            PRBool dontassert = PR_FALSE;
            PR_ASSERT(dontassert); /* set bkpoint here & set dontassert*/
        }
#endif

        if ((kind & SEC_ASN1_SKIP) ||
            (kind & SEC_ASN1_SAVE))
        {
            /* if skipping or saving this component, don't decode it */
            decode = PR_FALSE;
        }
    
        if (kind & (SEC_ASN1_SAVE | SEC_ASN1_OPTIONAL))
        {
            /* if saving this component, or if it is optional, we may not want to
               move past it, so save the position in case we have to rewind */
            mark = *src;
            if (kind & SEC_ASN1_SAVE)
            {
                save = PR_TRUE;
                if (0 == (kind & SEC_ASN1_SKIP))
                {
                    /* we will for sure have to rewind when saving this
                       component and not skipping it. This is true for all
                       legacy uses of SEC_ASN1_SAVE where the following entry
                       in the template would causes the same component to be
                       processed again */
                    pop = PR_TRUE;
                }
            }
        }

        rv = GetItem(src, &temp, PR_TRUE);
    }

    if (SECSuccess == rv)
    {
        /* now check if the component matches what we expect in the template */

        if (PR_TRUE == checkTag)

        {
            rv = MatchComponentType(templateEntry, &temp, &match, dest);
        }

        if ( (SECSuccess == rv) && (PR_TRUE != match) )
        {
            if (kind & SEC_ASN1_OPTIONAL)
            {

                /* the optional component is missing. This is not fatal. */
                /* Rewind, don't decode, and don't save */
                pop = PR_TRUE;
                decode = PR_FALSE;
                save = PR_FALSE;
            }
            else
            {
                /* a required component is missing. abort */
                PORT_SetError(SEC_ERROR_BAD_DER);
                rv = SECFailure;
            }
        }
    }

    if ((SECSuccess == rv) && (PR_TRUE == decode))
    {
        /* the order of processing here is is the tricky part */
        /* we start with our special cases */
        /* first, check the component class */
        if (kind & SEC_ASN1_INLINE)
        {
            /* decode inline template */
            rv = DecodeInline(dest, templateEntry, &temp , arena, PR_TRUE);
        }

        else
        if (kind & SEC_ASN1_EXPLICIT)
        {
            rv = DecodeExplicit(dest, templateEntry, &temp, arena);
        }
        else
        if ( (SEC_ASN1_UNIVERSAL != (kind & SEC_ASN1_CLASS_MASK)) &&

              (!(kind & SEC_ASN1_EXPLICIT)))
        {

            /* decode implicitly tagged components */
            rv = DecodeImplicit(dest, templateEntry, &temp , arena);
        }
        else
        if (kind & SEC_ASN1_POINTER)
        {
            rv = DecodePointer(dest, templateEntry, &temp, arena, PR_TRUE);
        }
        else
        if (kind & SEC_ASN1_CHOICE)
        {
            rv = DecodeChoice(dest, templateEntry, &temp, arena);
        }
        else
        if (kind & SEC_ASN1_ANY)
        {
            /* catch-all ANY type, don't decode */
            save = PR_TRUE;
            if (kind & SEC_ASN1_INNER)
            {
                /* skip the tag and length */
                SECItem newtemp = temp;
                rv = GetItem(&newtemp, &temp, PR_FALSE);
            }
        }
        else
        if (kind & SEC_ASN1_GROUP)
        {
            if ( (SEC_ASN1_SEQUENCE == (kind & SEC_ASN1_TAGNUM_MASK)) ||
                 (SEC_ASN1_SET == (kind & SEC_ASN1_TAGNUM_MASK)) )
            {
                rv = DecodeGroup(dest, templateEntry, &temp , arena);
            }
            else
            {
                /* a group can only be a SET OF or SEQUENCE OF */
                PORT_SetError(SEC_ERROR_BAD_TEMPLATE);
                rv = SECFailure;
            }
        }
        else
        if (SEC_ASN1_SEQUENCE == (kind & SEC_ASN1_TAGNUM_MASK))
        {
            /* plain SEQUENCE */
            rv = DecodeSequence(dest, templateEntry, &temp , arena);
        }
        else
        {
            /* handle all other types as "save" */
            /* we should only get here for primitive universal types */
            SECItem newtemp = temp;
            rv = GetItem(&newtemp, &temp, PR_FALSE);
            save = PR_TRUE;
            if ((SECSuccess == rv) &&
                SEC_ASN1_UNIVERSAL == (kind & SEC_ASN1_CLASS_MASK))
            {
                unsigned long tagnum = kind & SEC_ASN1_TAGNUM_MASK;
                if ( temp.len == 0 && (tagnum == SEC_ASN1_BOOLEAN ||
                                       tagnum == SEC_ASN1_INTEGER ||
                                       tagnum == SEC_ASN1_BIT_STRING ||
                                       tagnum == SEC_ASN1_OBJECT_ID ||
                                       tagnum == SEC_ASN1_ENUMERATED ||
                                       tagnum == SEC_ASN1_UTC_TIME ||
                                       tagnum == SEC_ASN1_GENERALIZED_TIME) )
                {
                    /* these types MUST have at least one content octet */
                    PORT_SetError(SEC_ERROR_BAD_DER);
                    rv = SECFailure;
                }
                else
                switch (tagnum)
                {
                /* special cases of primitive types */
                case SEC_ASN1_INTEGER:
                    {
                        /* remove leading zeroes if the caller requested
                           siUnsignedInteger
                           This is to allow RSA key operations to work */
                        SECItem* destItem = (SECItem*) ((char*)dest +
                                            templateEntry->offset);
                        if (destItem && (siUnsignedInteger == destItem->type))
                        {
                            while (temp.len > 1 && temp.data[0] == 0)
                            {              /* leading 0 */
                                temp.data++;
                                temp.len--;
                            }
                        }
                        break;
                    }

                case SEC_ASN1_BIT_STRING:
                    {
                        /* change the length in the SECItem to be the number
                           of bits */
                        temp.len = (temp.len-1)*8 - (temp.data[0] & 0x7);
                        temp.data++;
                        break;
                    }

                default:
                    {
                        break;
                    }
                }
            }
        }
    }

    if ((SECSuccess == rv) && (PR_TRUE == save))
    {
        SECItem* destItem = (SECItem*) ((char*)dest + templateEntry->offset);
        if (destItem)
        {
            /* we leave the type alone in the destination SECItem.
               If part of the destination was allocated by the decoder, in
               cases of POINTER, SET OF and SEQUENCE OF, then type is set to
               siBuffer due to the use of PORT_ArenaZAlloc*/
            destItem->data = temp.len ? temp.data : NULL;
            destItem->len = temp.len;
        }
        else
        {
            PORT_SetError(SEC_ERROR_INVALID_ARGS);
            rv = SECFailure;
        }
    }

    if (PR_TRUE == pop)
    {
        /* we don't want to move ahead, so restore the position */
        *src = mark;
    }
    return rv;
}