Esempio n. 1
0
File: vdw.c Progetto: tidatida/mpmc
//go through each molecule and determine the VDW energy associated with each isolated molecule
double sum_eiso_vdw ( system_t * system, double * sqrtKinv ) {

    char linebuf[MAXLINE];
    double e_iso = 0;
    molecule_t * mp;
    // atom_t * ap;  (unused variable)
    vdw_t * vp;
    vdw_t * vpscan;

    //loop through molecules. if not known, calculate, store and count. otherwise just count.
    for ( mp = system->molecules; mp; mp=mp->next ) {
        for ( vp = system->vdw_eiso_info; vp != NULL; vp=vp->next ) { //loop through all vp's
            if ( strncmp(vp->mtype,mp->moleculetype,MAXLINE) == 0 ) {
                e_iso += vp->energy; //count energy
                break; //break out of vp loop. the current molecule is accounted for now. go to the next molecule
            }
            else continue; //not a match, check the next vp
        } //vp loop

        if ( vp == NULL ) { //if the molecule was unmatched, we need to grow the list
            // end of vp list and we haven't matched yet -> grow vdw_eiso_info
            // scan to the last non-NULL element
            if ( system->vdw_eiso_info == NULL ) {
                system->vdw_eiso_info = calloc(1,sizeof(vdw_t)); //allocate space
                checknull(system->vdw_eiso_info,"calloc vdw_t * vdw_eiso_info",sizeof(vdw_t));
                vpscan = system->vdw_eiso_info; //set scan pointer
            } else {
                for ( vpscan = system->vdw_eiso_info; vpscan->next != NULL; vpscan=vpscan->next );
                vpscan->next = calloc(1,sizeof(vdw_t)); //allocate space
                checknull(vpscan->next,"calloc vdw_t * vpscan->next", sizeof(vdw_t));
                vpscan = vpscan->next;
            } //done scanning and malloc'ing

            //set values
            strncpy(vpscan->mtype,mp->moleculetype,MAXLINE); //assign moleculetype
            vpscan->energy = calc_e_iso(system,sqrtKinv,mp); //assign energy
            if ( isfinite(vpscan->energy) == 0 ) { //if nan, then calc_e_iso failed
                sprintf(linebuf,"VDW: Problem in calc_e_iso.\n");
                output(linebuf);
                die(-1);
            }
            //otherwise count the energy and move to the next molecule
            e_iso += vpscan->energy;

        } //vp==NULL
    } //mp loop

    ////all of this logic is actually really bad if we're doing surface fitting, since omega will change... :-(
    //free everything so we can recalc next step
    if ( system->ensemble == ENSEMBLE_SURF_FIT )  {
        free_vdw_eiso(system->vdw_eiso_info);
        system->vdw_eiso_info = NULL;
    }

    return e_iso;
}
Esempio n. 2
0
File: vdw.c Progetto: tidatida/mpmc
struct mtx * alloc_mtx ( int dim ) {
    //alloc matrix variable and set dim
    struct mtx * M = NULL;
    M = malloc(sizeof(struct mtx));
    checknull(M,"struct mtx * M", sizeof(struct mtx));
    M->dim=dim;
    //alloc matrix storage space
    M->val=calloc(dim*dim,sizeof(double));
    checknull(M->val,"struct mtx * M->val", dim*dim*sizeof(double));
    return M;
}
Esempio n. 3
0
File: vdw.c Progetto: tidatida/mpmc
/* LAPACK using 1D arrays for storing matricies.
	/ 0  3  6 \
	| 1  4  7 |		= 	[ 0 1 2 3 4 5 6 7 8 ]
	\ 2  5  8 /									*/
double * lapack_diag ( struct mtx * M, int jobtype ) {
    char job; //job type
    char uplo='L'; //operate on lower triagle
    double * work; //working space for dsyev
    int lwork; //size of work array
    int rval=0; //returned from dsyev_
    double * eigvals;
    char linebuf[MAXLINE];

    //eigenvectors or no?
    if ( jobtype == 2 ) job='V';
    else job = 'N';

    if ( M->dim == 0 ) return NULL;

    //allocate eigenvalues array
    eigvals = malloc(M->dim*sizeof(double));
    checknull(eigvals,"double * eigvals",M->dim*sizeof(double));
    //optimize the size of work array
    lwork = -1;
    work = malloc(sizeof(double));
    checknull(work,"double * work",sizeof(double));
    dsyev_(&job, &uplo, &(M->dim), M->val, &(M->dim), eigvals, work, &lwork, &rval);
    //now optimize work array size is stored as work[0]
    lwork=(int)work[0];
    work = realloc(work,lwork*sizeof(double));
    checknull(work,"double * work",lwork*sizeof(double));
    //diagonalize
    dsyev_(&job, &uplo, &(M->dim), M->val, &(M->dim), eigvals, work, &lwork, &rval);

    if ( rval != 0 ) {
        sprintf(linebuf,"error: LAPACK: dsyev returned error: %d\n", rval);
        error(linebuf);
        die(-1);
    }

    free(work);

    return eigvals;
}
unsigned int
find_libc(char *syscall)
{
	void *s;
	unsigned int syscall_addr;

	if (!(s = dlopen(NULL, RTLD_LAZY)))
		errx(1, "error: dlopen() failed");

	if (!(syscall_addr = (unsigned int)dlsym(s, syscall)))
		errx(1, "error: dlsym() %s", syscall);

	printf("[-] %s(): 0x%x\n", syscall, syscall_addr);
	checknull(syscall_addr);
	return(syscall_addr);

	return(1);
}
Esempio n. 5
0
File: vdw.c Progetto: tidatida/mpmc
//build the matrix K^(-1/2) -- see the PDF
double * getsqrtKinv ( system_t * system, int N ) {
    double * sqrtKinv;
    molecule_t * molecule_ptr;
    atom_t * atom_ptr;
    int i = 0;

    //malloc 3*N wastes an insignificant amount of memory, but saves us a lot of index management
    sqrtKinv = malloc(3*N*sizeof(double));
    checknull(sqrtKinv,"double * sqrtKinv",3*N*sizeof(double));

    for ( molecule_ptr = system->molecules; molecule_ptr; molecule_ptr=molecule_ptr->next ) {
        for ( atom_ptr = molecule_ptr->atoms; atom_ptr; atom_ptr = atom_ptr->next ) {
            //Seek through atoms, calculate sqrtKinv*
            sqrtKinv[i] = sqrt(atom_ptr->polarizability)*atom_ptr->omega;
            sqrtKinv[i+1] = sqrt(atom_ptr->polarizability)*atom_ptr->omega;
            sqrtKinv[i+2] = sqrt(atom_ptr->polarizability)*atom_ptr->omega;
            i+=3;
        }
    }

    return sqrtKinv;
}
unsigned int
find_string(char *string)
{
	unsigned int i;
	char *a;

	printf("[-] %s: ", string);

	signal(SIGSEGV, fail);

	for (i = 0xb0300000; i < 0xdeadbeef; i++) {
		a = i;

		if (strcmp(a, string) != 0)
			continue;

		printf("0x%x\n", i);
		checknull(i);

		return(i);
	}

	return(1);
}