예제 #1
0
static int
PyFFEnergyTerm_init(PyObject *self_po, PyObject *args, PyObject *kw)
{
  PyFFEnergyTermObject *self = (PyFFEnergyTermObject *)self_po;
  char *name;
  PyObject *universe;
  PyObject *term_names;
  int thread_safe = 0;
  int i;
  if (! PyArg_ParseTuple(args, "OsO!|i",
			 &universe, &name,
			 &PyTuple_Type, &term_names,
			 &thread_safe))
        return -1; 
  self->nterms = (int)PyTuple_Size(term_names);
  if (self->nterms == 0) {
    PyErr_SetString(PyExc_ValueError, "at least one term name required");
    return -1;
  }
  if (self->nterms > MMTK_MAX_TERMS) {
    PyErr_SetString(PyExc_ValueError, "too many terms");
    return -1;
  }
  self->universe_spec = (PyUniverseSpecObject *)
                        PyObject_GetAttrString(universe, "_spec");
  if (self->universe_spec == NULL)
    return -1;
  Py_INCREF(self->universe_spec);
  self->evaluator_name = allocstring(name);
  if (self->evaluator_name == NULL) {
    PyErr_NoMemory();
    return -1;
  }
  for (i = 0; i < self->nterms; i++) {
    PyObject *name = PyTuple_GetItem(term_names, (Py_ssize_t)i);
    if (!PyString_Check(name)) {
      PyErr_SetString(PyExc_TypeError, "term names must be strings");
      return -1;
    }
    self->term_names[i] = allocstring(PyString_AsString(name));
    if (self->term_names[i] == NULL) {
      PyErr_NoMemory();
      return -1;
    }
  }
  self->thread_safe = thread_safe;
  return 0;
}
예제 #2
0
struct symbol*
setsymbol(const char *symname, struct value *val)
{
	struct symbol *sym;

	/* search for a matching symbol name */
	sym = findsymbol(symname);

	/* if there isn't one, add a new to the end of the list */
	if(!sym){
		sym = getlastsymbol();
		sym->sym_next = xmalloc(sizeof(struct symbol));
		sym = sym->sym_next;

		/* set the name, ensure list integrity and move along as
		 * if nothing happened */
		sym->name = allocstring(symname);
		sym->sym_next = NULL;
	}
	/* if a symbol existed, clear the old value */
	else freeval(&sym->val);

	setval(&sym->val, val);
	return sym;
}
예제 #3
0
static PyObject *
PoseDihedralTerm(PyObject *dummy, PyObject *args)
{
  PyFFEnergyTermObject *self;
  char *name = "pose dihedral angle";
  self = PyFFEnergyTerm_New();
  if (self == NULL)
    return NULL;
  if (!PyArg_ParseTuple(args, "O!OO|s",
                        &PyUniverseSpec_Type, &self->universe_spec,
                        &self->data[0], &self->data[1],
                        &name))
    return NULL;
  self->evaluator_name = "pose dihedral angle";
  self->term_names[0] = allocstring(name);
  if (self->term_names[0] == NULL)
    return PyErr_NoMemory();
  Py_INCREF(self->universe_spec);
  Py_INCREF(self->data[0]);
  Py_INCREF(self->data[1]);
  self->n = ((PyArrayObject *)self->data[0])->dimensions[0];
  self->nterms = 1;
  self->eval_func = pose_dihedral_evaluator;
  self->threaded = 1;
  self->thread_safe = 1;
  self->nbarriers = 0;
  self->parallelized = 1;
  return (PyObject *)self;
}
예제 #4
0
파일: edit.c 프로젝트: npe9/harvey
String*
getregexp(int delim)
{
	String *buf, *r;
	int i, c;

	buf = allocstring(0);
	for(i=0; ; i++){
		if((c = getch())=='\\'){
			if(nextc()==delim)
				c = getch();
			else if(nextc()=='\\'){
				Straddc(buf, c);
				c = getch();
			}
		}else if(c==delim || c=='\n')
			break;
		if(i >= RBUFSIZE)
			editerror("regular expression too long");
		Straddc(buf, c);
	}
	if(c!=delim && c)
		ungetch();
	if(buf->n > 0){
		patset = TRUE;
		freestring(lastpat);
		lastpat = buf;
	}else
		freestring(buf);
	if(lastpat->n == 0)
		editerror("no regular expression defined");
	r = newstring(lastpat->n);
	runemove(r->r, lastpat->r, lastpat->n);	/* newstring put \0 at end */
	return r;
}
예제 #5
0
static PyObject *
ListOfNParticleTerms(PyObject *args, ff_eterm_function f,
		     char *eval_name, char *default_term_name)
{
  PyFFEnergyTermObject *self;
  char *name = default_term_name;
  self = PyFFEnergyTerm_New();
  if (self == NULL)
    return NULL;
  if (!PyArg_ParseTuple(args, "O!OO|s",
			&PyUniverseSpec_Type, &self->universe_spec,
			&self->data[0], &self->data[1],
			&name))
    return NULL;
  self->evaluator_name = eval_name;
  self->term_names[0] = allocstring(name);
  if (self->term_names[0] == NULL)
    return PyErr_NoMemory();
  Py_INCREF(self->universe_spec);
  Py_INCREF(self->data[0]);  /* indices */
  Py_INCREF(self->data[1]);  /* parameters */
  self->n = ((PyArrayObject *)self->data[0])->dimensions[0];
  self->nterms = 1;
  self->eval_func = f;
  self->threaded = 1;
  self->thread_safe = 1;
  self->nbarriers = 0;
  self->parallelized = 1;
  return (PyObject *)self;
}
예제 #6
0
파일: edit.c 프로젝트: npe9/harvey
String*
newstring(int n)
{
	String *p;

	p = allocstring(n);
	inslist(&stringlist, stringlist.nused, p);
	return p;
}
예제 #7
0
파일: main.c 프로젝트: leffmann/vlink
static void  ReadListFile(struct GlobalVars *gv,char *name,uint16_t flags)
/* read a file, which contains a list of object file names */
{
  FILE *f;
  struct InputFile *ifn;
  int c;
  char buf[256],*n=NULL;

  if (f = fopen(name,"r")) {
    do {
      int len = 0;

      c = fgetc(f);
      if (c == '\"') {  /* read file name in quotes */
        n = buf;
        len = 0;
        while ((c = fgetc(f))!=EOF && c!='\"') {
          if (len < 255) {
            len++;
            *n++ = c;
          }
        }
      }
      else if (c > ' ') {
        if (n == NULL) {
          n = buf;
          len = 0;
        }
        if (len < 255) {
          len++;
          *n++ = c;
        }
      }
      if (c<=' ' && n) {  /* file name ends here */
        *n = 0;
        ifn = alloc(sizeof(struct InputFile));
        ifn->name = allocstring(buf);
        ifn->lib = FALSE;
        ifn->flags = flags;
        addtail(&gv->inputlist,&ifn->n);
        n = NULL;
      }
    }
    while (c != EOF);
    fclose(f);
  }
  else
    error(8,name);  /* cannot open */
}
예제 #8
0
파일: t_vobj.c 프로젝트: deplinenoise/vlink
static void vobj_readconv(struct GlobalVars *gv,struct LinkFile *lf)
{
  if (lf->type == ID_LIBARCH) {
    if (ar_init(&ai,(char *)lf->data,lf->length,lf->filename)) {
      while (ar_extract(&ai)) {
        lf->objname = allocstring(ai.name);
        vobj_read(gv,lf,(uint8_t *)ai.data);
      }
    }
    else
      ierror("vobj_readconv(): archive %s corrupted since last access",
             lf->pathname);
  }
  else {
    lf->objname = lf->filename;
    vobj_read(gv,lf,lf->data);
  }
}
예제 #9
0
파일: edit.c 프로젝트: npe9/harvey
void
editcmd(Text *ct, Rune *r, uint n)
{
	char *err;

	if(n == 0)
		return;
	if(2*n > RBUFSIZE){
		warning(nil, "string too long\n");
		return;
	}

	allwindows(alleditinit, nil);
	if(cmdstartp)
		free(cmdstartp);
	cmdstartp = runemalloc(n+2);
	runemove(cmdstartp, r, n);
	if(r[n] != '\n')
		cmdstartp[n++] = '\n';
	cmdstartp[n] = '\0';
	cmdendp = cmdstartp+n;
	cmdp = cmdstartp;
	if(ct->w == nil)
		curtext = nil;
	else
		curtext = &ct->w->body;
	resetxec();
	if(editerrc == nil){
		editerrc = chancreate(sizeof(char*), 0);
		lastpat = allocstring(0);
	}
	threadcreate(editthread, nil, STACK);
	err = recvp(editerrc);
	editing = Inactive;
	if(err != nil){
		if(err[0] != '\0')
			warning(nil, "Edit: %s\n", err);
		free(err);
	}

	/* update everyone whose edit log has data */
	allwindows(allupdate, nil);
}
예제 #10
0
/* The next function is meant to be called from Python. It creates the
   energy term object at the C level and stores all the parameters in
   there in a form that is convient to access for the C routine above.
   This is the routine that is imported into and called by the Python
   module, HarmonicOscillatorFF.py. */
static PyObject *
HarmonicOscillatorTerm(PyObject *dummy, PyObject *args)
{
  PyFFEnergyTermObject *self;
  int atom_index;
  double x, y, z;
  double force_constant;

  /* Create a new energy term object and return if the creation fails. */
  self = PyFFEnergyTerm_New();
  if (self == NULL)
    return NULL;
  /* Convert the parameters to C data types. */
  if (!PyArg_ParseTuple(args, "O!idddd",
                        &PyUniverseSpec_Type, &self->universe_spec,
                        &atom_index, &x, &y, &z, &force_constant))
    return NULL;
  /* We keep a reference to the universe_spec in the newly created
     energy term object, so we have to increase the reference count. */
  Py_INCREF(self->universe_spec);
  /* A pointer to the evaluation routine. */
  self->eval_func = harmonic_evaluator;
  /* The name of the energy term object. */
  self->evaluator_name = "harmonic_oscillator";
  /* The names of the individual energy terms - just one here. */
  self->term_names[0] = allocstring("harmonic_oscillator");
  if (self->term_names[0] == NULL)
    return PyErr_NoMemory();
  self->nterms = 1;
  /* self->param is a storage area for parameters. Note that there
     are only 40 slots (double) there, if you need more space, you can use
     self->data, an array for up to 40 Python object pointers. */
  self->param[0] = x;
  self->param[1] = y;
  self->param[2] = z;
  self->param[3] = force_constant;
  self->param[4] = (double) atom_index;
  /* Return the energy term object. */
  return (PyObject *)self;
}
예제 #11
0
/* The next function is meant to be called from Python. It creates the
   energy term object at the C level and stores all the parameters in
   there in a form that is convient to access for the C routine above.
   This is the routine that is imported into and called by the Python
   module, ElectricField.py. */
static PyObject *
ElectricFieldTerm_z(PyObject *dummy, PyObject *args)
{
  PyFFEnergyTermObject *self;
  PyArrayObject *charges;
  double z;

  /* Create a new energy term object and return if the creation fails. */
  self = PyFFEnergyTerm_New();
  if (self == NULL)
    return NULL;
  /* Convert the parameters to C data types. */
  if (!PyArg_ParseTuple(args, "O!O!d",
			&PyUniverseSpec_Type, &self->universe_spec,
			&PyArray_Type, &charges, &z))
    return NULL;
  /* We keep a reference to the universe_spec in the newly created
     energy term object, so we have to increase the reference count. */
  Py_INCREF(self->universe_spec);
  /* A pointer to the evaluation routine. */
  self->eval_func = ef_evaluator;
  /* The name of the energy term object. */
  self->evaluator_name = "electric_field_z";
  /* The names of the individual energy terms - just one here. */
  self->term_names[0] = allocstring("electric_field_z");
  if (self->term_names[0] == NULL)
    return PyErr_NoMemory();
  self->nterms = 1;
  /* self->param is a storage area for parameters. Note that there
     are only 40 slots (double) there. */
  self->param[2] = z;
  /* self->data is the other storage area for parameters. There are
     40 Python object slots there */
  self->data[0] = (PyObject *)charges;
  Py_INCREF(charges);
  /* Return the energy term object. */
  return (PyObject *)self;
}
예제 #12
0
static void armle_readconv(struct GlobalVars *gv,struct LinkFile *lf)
/* Read ELF-ARM little-endian executable / object / shared obj. */
{
  if (lf->type == ID_LIBARCH) {
    struct ar_info ai;

    if (ar_init(&ai,(char *)lf->data,lf->length,lf->filename)) {
      while (ar_extract(&ai)) {
        lf->objname = allocstring(ai.name);
        elf32_check_ar_type(fff[lf->format],lf->pathname,
                            (struct Elf32_Ehdr *)ai.data,
                            ELFCLASS32,ELFDATA2LSB,ELF_VER,1,EM_ARM);
        elf32_parse(gv,lf,(struct Elf32_Ehdr *)ai.data,armle_reloc_elf2vlink);
      }
    }
    else
      ierror("armle_readconv(): archive %s corrupted since last access",
             lf->pathname);
  }
  else {
    lf->objname = lf->filename;
    elf32_parse(gv,lf,(struct Elf32_Ehdr *)lf->data,armle_reloc_elf2vlink);
  }
}
예제 #13
0
int
s_yylex()
{
	register c;
	register char *cp;
	int f;
	char delim;

if (yylineno == 0)
	incrlineno();

while(1) {
	/*
	 * skip white space
	 */
	if (c = lookaheadchar ) {
		lookaheadchar = 0;
		}
	 else
		c = readkey();

	cp = yytext;
	while (c == ' ' || c == '\t' || c == 0 || c == 12 /* FF */) {
		c = readkey();
	}
	yytext[0] = c; yytext[1] = yytext[2] = 0;
	if( isascii(c) && (isalpha( c ) || c == '_') ) {
		do {
			*cp++ = c;
			c = readkey();
		} while (isascii(c) && (isalnum(c) || c == '_'));
		*cp = 0;

		lookaheadchar = c;
		c = look_kw(yytext);
		clearla();
		if (c == 0) {
			yylval.strval = allocstring(yytext);
			return (YID);
			}
		return c;
		}

	else if( isascii(c) && isdigit(c) ) {
		f = 0;
		do {
			*cp++ = c;
			c = readkey();
		} while (isascii(c) && isdigit(c));
		if (c == '.') {
			c = readkey();
			if (c == '.') {
				*cp = 0;
				lookaheadchar = YDOTDOT;
				yylval.strval = allocstring(yytext);
				return (YINT);
			}
infpnumb:
			f++;
			*cp++ = '.';
			if (!isascii(c) || !isdigit(c)) {
				scanerror("syntax error: digits required after decimal point");
				*cp++ = '0';
			} else
				while (isdigit(c)) {
					*cp++ = c;
					c = readkey();
				}
		}
		if (c == 'e' || c == 'E') {
			f++;
			*cp++ = c;
			if ((c = lookaheadchar) == 0)
				c = readkey();
			if (c == '+' || c == '-') {
				*cp++ = c;
				c = readkey();
			}
			if (!isascii(c) || !isdigit(c)) {
				scanerror("syntax error: digits required in exponent");
				*cp++ = '0';
			} else
				while (isascii(c) && isdigit(c)) {
					*cp++ = c;
					c = readkey();
				}
		}
		*cp = 0;
		lookaheadchar = c;
		clearla();
		yylval.strval = allocstring(yytext);
		if (f)
			return (YNUMB);
		return (YINT);
		}
	printt2("Select on char %d - %c\n", c, c );
	switch (c) {
	case EOF:
		return 0;
	case ' ':
	case '\t':
	case 12: /* form feed */
		break;
	case '"':
	case '\'':
		*cp++ = delim = c;
		do {
			do {
				c = readkey();
				if (c == '\n' || c == EOFCHAR) {
					scanerror("syntax error: unmatched quote for string" );
					if (cp == yytext)
						*cp++ = ' ', cp++;
					return YILLCH;
				}
				*cp++ = c;
			} while (c != delim);
			c = readkey();
		} while (c == delim);
		if( c == '^' || c== '#' ) {
			par_error( "Can't imbed ^A or #nnn codes in strings.  Try concatenating strings together\n" );
			}
		*--cp = 0;
#ifndef TURBO
		if (cp == yytext && delim == '\'') {
			scanerror("syntax error: null string not allowed");
			*cp++ = ' ';
			*cp++ = 0;
		}
#endif
		lookaheadchar = c;
		clearla();
		/* len of 2 means 1 char and 1 quote char */
		if (delim == '"' || strlen(yytext) != 2) {
			yylval.strval = allocstring(yytext);
			return (YSTRING);
			}
		else  {
			yylval.intval = yytext[1];
			return (YCHAR);
			}
	case '.':
		c = readkey();
		if (c == '.')
			return (YDOTDOT);
		if (isdigit(c)) {
			scanerror("syntax error: digits required before decimal point");
			*cp++ = '0';
			goto infpnumb;
		}
		lookaheadchar = c;
		clearla();
		return '.';

	case '\n':
		break;
	case '{': /* { ... } comment */
		delim = '{';
comment:
		c = readkey();
#ifdef TURBO
		if (c == '$' && turbo_flag) {
			f = scanturbo();
			if (f >= 0)
				return f;
			}
		else
#endif
		if (c == '+') {
			/* Stubs generated by alist, we know they use {} */
			f = scanstub();
			if (f == YC_BLCOMMENT) {
				/* Kludge - throw away to keep grammar LALR.
				 * Doesn't matter since they will be generated
				 * in all appropriate places anyway.
				 */
				continue;	/* outer while loop */
			}
			if (f >= 0)
				return f;
		}
		else {
			for (;;) {
				if (delim=='{' && c == '}') {
					break;
				}
				if (c == '\n') {
					/* Break into one line pieces */
					*cp++ = 0;
					savecomment(yytext);
					cp = yytext;
					*cp = 0;
				} else {
					*cp++ = c;
					if (c <= 0) {
						/* nonterminated comment */
						/* This "can't happen" */
						fatal("Bug - nonterm comment");
					}
				}
				c = readkey();
				if (delim=='(' && c == ')' && cp[-1] == '*') {
					*--cp = 0;
					break;
				}
			}
			*cp++ = 0;
		}
		/*
		 * Comments generated by the lister for procedure or
		 * function calls (in parens, ending in =) are ignored.
		 */
		if (parendepth <= 0 || cp[-2] != '=')
			savecomment(yytext);
		clearla();
		cp = yytext;
		*cp = 0;
		if (allowcom)
			return 0;
		break;
	case ':':
		if ((c=readkey()) == '=') {
			*++cp = c;
			return YCOLEQUALS;
			}
		lookaheadchar = c;
		clearla();
		return ':';
	case '(':
		if ((c=readkey()) == '*') {
			delim = '(';
			goto comment;
			}
		lookaheadchar = c;
		clearla();
		parendepth++;
		return '(';
	case ')':
		parendepth--;
		return ')';
	case '$':
		while( isxdigit(c = readkey()) )
			*++cp = c;
		*++cp = 0;
		lookaheadchar = c;
		if( strlen(yytext) <= 1 )	
			return YILLCH;
		yylval.strval = allocstring(yytext);
		return YINT;
	case '#':
		c = readkey();
		if( c == '$' ) {
			unsigned hxnum;
			while( isxdigit(c = readkey()) )
				hxnum = (hxnum << 4) + ((c > '9') ? 9 : 0)
					+ (c & 0xf);

			lookaheadchar = c;
			yylval.intval = hxnum;
			return YCHAR;
			}
		else while (isdigit(c)) {
			*++cp = c;
			c = readkey();
			}
		*++cp = 0;
		lookaheadchar = c;
		yylval.intval = atoi(&yytext[1]);
		return YCHAR;
	case '^':
		c = readkey();
		if (strchr("\\_", c)) {		/* others include []@^ */
			yylval.intval = c & 0x1f;
			return YCHAR;
		}
		else {
			lookaheadchar = c;
			yylval.intval = '^';
			return YPTR;
		}
	case '@':
		yylval.intval = '@';
		return YPTR;
	case ';':
	case ',':
	case '=':
	case '*':
	case '+':
	case '/':
	case '-':
	case '[':
	case ']':
	case '<':
	case '>':
	case '_':
	case '\\':
	case '}':	/* for DO..SET */
		return c;
	case YDOTDOT:
		return YDOTDOT;

	default:
		if (c <= 0)
			return (0);
		do
			lookaheadchar = readkey();
		while (lookaheadchar == c);
		clearla();
		printt1("illegal char in scanner %o\n", c);
		return (YILLCH);
	}
  
  } /* big while */
}
예제 #14
0
/* The next function is meant to be called from Python. It creates the
   energy term object at the C level and stores all the parameters in
   there in a form that is convient to access for the C routine above.
   This is the routine that is imported into and called by the Python
   module, OBC.py. */
static PyObject *
OBCTerm(PyObject *dummy, PyObject *args)
{
  PyFFEnergyTermObject *self;
  int numParticles;
  PyArrayObject *charges;
  PyArrayObject *atomicRadii;
  PyArrayObject *scaleFactors;
  double strength;

  /* Create a new energy term object and return if the creation fails. */
  self = PyFFEnergyTerm_New();
  if (self == NULL)
    return NULL;
  /* Convert the parameters to C data types. */
  if (!PyArg_ParseTuple(args, "O!idO!O!O!",
			&PyUniverseSpec_Type, &self->universe_spec,
      &numParticles, &strength,
			&PyArray_Type, &charges,
      &PyArray_Type, &atomicRadii,
      &PyArray_Type, &scaleFactors))
    return NULL;
  /* We keep a reference to the universe_spec in the newly created
     energy term object, so we have to increase the reference count. */
  Py_INCREF(self->universe_spec);
  /* A pointer to the evaluation routine. */
  self->eval_func = ef_evaluator;
  /* The name of the energy term object. */
  self->evaluator_name = "OBC";
  /* The names of the individual energy terms - just one here. */
  self->term_names[0] = allocstring("OBC");
  if (self->term_names[0] == NULL)
    return PyErr_NoMemory();
  self->nterms = 1;
  
  struct ObcParameters* obcParameters = newObcParameters(
    numParticles, strength, (double *)charges->data,
    (double *)atomicRadii->data, (double *)scaleFactors->data);
  struct ReferenceObc* obc = newReferenceObc(obcParameters);

  /* self->param is a storage area for parameters. Note that there
     are only 40 slots (double) there. */
  self->param[0] = (double) numParticles;
  self->param[1] = strength;
  
  /* self->data is the other storage area for parameters. There are
     40 Python object slots there */
  self->data[0] = (PyObject *)charges;
  Py_INCREF(charges);
  self->data[1] = (PyObject *)atomicRadii;
  Py_INCREF(atomicRadii);
  self->data[2] = (PyObject *)scaleFactors;
  Py_INCREF(scaleFactors);
  self->data[3] = (PyObject *)obcParameters;
  Py_INCREF(obcParameters); // Seems to increment the number of particles
  setNumberOfAtoms(obcParameters, numParticles);
  self->data[4] = (PyObject *)obc;
  Py_INCREF(obc);
  
  /* Return the energy term object. */
  return (PyObject *)self;
}