Example #1
0
int parse_bondlist(NLEnergy *p, Tcl_Interp *interp,
    Tcl_Obj *const obj, boolean invert) {
  char *bondsel = Array_data(&(p->bondsel));
  char *invsel = Array_data(&(p->invsel));
  char *sel = (invert ? invsel : bondsel);
  const int32 nbonds = Topology_bond_array_length(&(p->topo));
  int32 id;
  Tcl_Obj **objv;
  int objc, n;

  if (invert) {
    memset(invsel, 0, nbonds);
  }
  if ((id=parse_bond(p,interp,obj)) >= 0) {  /* could be a singleton */
    sel[id] = TRUE;
  }
  else {  /* could be a list of bonds */
    if (TCL_ERROR==Tcl_ListObjGetElements(interp, obj, &objc, &objv)) {
      return FAIL;
    }
    for (n = 0;  n < objc;  n++) {
      if ((id=parse_bond(p,interp,objv[n])) < 0) {
        return FAIL;
      }
      sel[id] = TRUE;
    }
  }
  if (invert) {
    for (id = 0;  id < nbonds;  id++) {
      if (FALSE==invsel[id]) bondsel[id] = TRUE;
    }
  }
  return OK;
}
Example #2
0
void read_str_file()
{
    int len = 1024;
    int readed = -1;
    STR buff;
    int file_line = 0;
    FILE* str_file;
    if( str_filename == NULL ) UNERR("str_filename not defined");

    buff = (STR) malloc( sizeof(char) * len );
    CHMEM(buff);

    str_file = fopen( str_filename, "r" );
    if( str_file == NULL ) UNERR("Can't open str-file");
    while( fgets( buff, len, str_file ) )
    {
        if( readed ) /*Non empty line*/
        {
            char* pos = strchr( buff, COMMENT_SIGN );
            char* keyword;
            file_line++;
            if( pos ) *pos = '\0'; /* 'remove' comment */
            if( !strlen(buff) ) continue;

            keyword = strtok( buff, " \t\n" );
            if( !keyword ) continue; /* ok we have only spaces and tabs */

            if( strcmp( keyword , SUB_TAG ) == 0 )
            {
                parse_sub();
            }
            else if( strcmp( keyword, BOND_TAG ) == 0 )
            {
                parse_bond();
            }
            else if( strcmp( keyword, ANGLE_TAG ) == 0 )
            {
                parse_angle();
            }
            else if( strcmp( keyword, DIHE_TAG ) == 0 )
            {
                parse_dihe();
            }
            else
            {
                warning( keyword, __FILE__, __LINE__ );
                UNERR( "Unknow tag in str file" );
            }
        }
    }
    end_sub();
    end_angle();
    end_angle_cos();
    end_dihe();
    end_dihe_angle();
    end_bond();

    free( buff );
    fclose( str_file );

    center_coords();/* Center coordinates */
}