示例#1
0
colvar::distance_inv::distance_inv(std::string const &conf)
  : cvc(conf)
{
  function_type = "distance_inv";

  group1 = parse_group(conf, "group1");
  group2 = parse_group(conf, "group2");

  get_keyval(conf, "exponent", exponent, 6);
  if (exponent%2) {
    cvm::error("Error: odd exponent provided, can only use even ones.\n");
    return;
  }
  if (exponent <= 0) {
    cvm::error("Error: negative or zero exponent provided.\n");
    return;
  }

  for (cvm::atom_iter ai1 = group1->begin(); ai1 != group1->end(); ai1++) {
    for (cvm::atom_iter ai2 = group2->begin(); ai2 != group2->end(); ai2++) {
      if (ai1->id == ai2->id) {
        cvm::error("Error: group1 and group2 have some atoms in common: this is not allowed for distanceInv.\n");
        return;
      }
    }
  }

  x.type(colvarvalue::type_scalar);
}
示例#2
0
colvar::distance_pairs::distance_pairs(std::string const &conf)
  : cvc(conf)
{
  function_type = "distance_pairs";

  group1 = parse_group(conf, "group1");
  group2 = parse_group(conf, "group2");

  x.type(colvarvalue::type_vector);
  enable(f_cvc_implicit_gradient);
  x.vector1d_value.resize(group1->size() * group2->size());
}
colvar::distance_z::distance_z(std::string const &conf)
  : cvc(conf)
{
  function_type = "distance_z";
  b_inverse_gradients = true;
  b_Jacobian_derivative = true;
  x.type(colvarvalue::type_scalar);

  // TODO detect PBC from MD engine (in simple cases)
  // and then update period in real time
  if (period != 0.0)
    b_periodic = true;

  if ((wrap_center != 0.0) && (period == 0.0)) {
    cvm::error("Error: wrapAround was defined in a distanceZ component,"
                " but its period has not been set.\n");
    return;
  }

  parse_group(conf, "main", main);
  parse_group(conf, "ref", ref1);
  atom_groups.push_back(&main);
  atom_groups.push_back(&ref1);
  // this group is optional
  parse_group(conf, "ref2", ref2, true);

  if (ref2.size()) {
    atom_groups.push_back(&ref2);
    cvm::log("Using axis joining the centers of mass of groups \"ref\" and \"ref2\"");
    fixed_axis = false;
    if (key_lookup(conf, "axis"))
      cvm::log("Warning: explicit axis definition will be ignored!");
  } else {
    if (get_keyval(conf, "axis", axis, cvm::rvector(0.0, 0.0, 1.0))) {
      if (axis.norm2() == 0.0) {
        cvm::error("Axis vector is zero!");
        return;
      }
      if (axis.norm2() != 1.0) {
        axis = axis.unit();
        cvm::log("The normalized axis is: "+cvm::to_str(axis)+".\n");
      }
    }
    fixed_axis = true;
  }

  if (get_keyval(conf, "forceNoPBC", b_no_PBC, false)) {
    cvm::log("Computing distance using absolute positions (not minimal-image)");
  }
  if (get_keyval(conf, "oneSiteSystemForce", b_1site_force, false)) {
    cvm::log("Computing system force on group \"main\" only");
  }
}
示例#4
0
colvar::dipole_angle::dipole_angle(std::string const &conf)
  : cvc(conf)
{
  function_type = "dipole_angle";
  group1 = parse_group(conf, "group1");
  group2 = parse_group(conf, "group2");
  group3 = parse_group(conf, "group3");

  if (get_keyval(conf, "oneSiteSystemForce", b_1site_force, false)) {
    cvm::log("Computing system force on group 1 only");
  }
  x.type(colvarvalue::type_scalar);
}
示例#5
0
colvar::distance_z::distance_z(std::string const &conf)
  : cvc(conf)
{
  function_type = "distance_z";
  provide(f_cvc_inv_gradient);
  provide(f_cvc_Jacobian);
  enable(f_cvc_com_based);
  x.type(colvarvalue::type_scalar);

  // TODO detect PBC from MD engine (in simple cases)
  // and then update period in real time
  if (period != 0.0)
    b_periodic = true;

  if ((wrap_center != 0.0) && (period == 0.0)) {
    cvm::error("Error: wrapAround was defined in a distanceZ component,"
                " but its period has not been set.\n");
    return;
  }

  main = parse_group(conf, "main");
  ref1 = parse_group(conf, "ref");
  // this group is optional
  ref2 = parse_group(conf, "ref2", true);

  if (ref2 && ref2->size()) {
    cvm::log("Using axis joining the centers of mass of groups \"ref\" and \"ref2\"");
    fixed_axis = false;
    if (key_lookup(conf, "axis"))
      cvm::log("Warning: explicit axis definition will be ignored!");
  } else {
    if (get_keyval(conf, "axis", axis, cvm::rvector(0.0, 0.0, 1.0))) {
      if (axis.norm2() == 0.0) {
        cvm::error("Axis vector is zero!");
        return;
      }
      if (axis.norm2() != 1.0) {
        axis = axis.unit();
        cvm::log("The normalized axis is: "+cvm::to_str(axis)+".\n");
      }
    }
    fixed_axis = true;
  }

  if (get_keyval(conf, "forceNoPBC", b_no_PBC, false)) {
    cvm::log("Computing distance using absolute positions (not minimal-image)");
  }

  init_total_force_params(conf);

}
示例#6
0
colvar::distance_pairs::distance_pairs(std::string const &conf)
  : cvc(conf)
{
  function_type = "distance_pairs";

  if (get_keyval(conf, "forceNoPBC", b_no_PBC, false)) {
    cvm::log("Computing distance using absolute positions (not minimal-image)");
  }

  group1 = parse_group(conf, "group1");
  group2 = parse_group(conf, "group2");

  x.type(colvarvalue::type_vector);
  x.vector1d_value.resize(group1->size() * group2->size());
}
示例#7
0
colvar::distance::distance(std::string const &conf)
  : cvc(conf)
{
  function_type = "distance";
  provide(f_cvc_inv_gradient);
  provide(f_cvc_Jacobian);
  enable(f_cvc_com_based);

  group1 = parse_group(conf, "group1");
  group2 = parse_group(conf, "group2");

  init_total_force_params(conf);

  x.type(colvarvalue::type_scalar);
}
示例#8
0
colvar::cartesian::cartesian(std::string const &conf)
  : cvc(conf)
{
  function_type = "cartesian";

  atoms = parse_group(conf, "atoms");

  bool use_x, use_y, use_z;
  get_keyval(conf, "useX", use_x, true);
  get_keyval(conf, "useY", use_y, true);
  get_keyval(conf, "useZ", use_z, true);

  axes.clear();
  if (use_x) axes.push_back(0);
  if (use_y) axes.push_back(1);
  if (use_z) axes.push_back(2);

  if (axes.size() == 0) {
    cvm::error("Error: a \"cartesian\" component was defined with all three axes disabled.\n");
    return;
  }

  x.type(colvarvalue::type_vector);
  enable(f_cvc_implicit_gradient);
  x.vector1d_value.resize(atoms->size() * axes.size());
}
示例#9
0
colvar::angle::angle(std::string const &conf)
  : cvc(conf)
{
  function_type = "angle";
  provide(f_cvc_inv_gradient);
  provide(f_cvc_Jacobian);
  provide(f_cvc_com_based);

  group1 = parse_group(conf, "group1");
  group2 = parse_group(conf, "group2");
  group3 = parse_group(conf, "group3");
  if (get_keyval(conf, "oneSiteSystemForce", b_1site_force, false)) {
    cvm::log("Computing system force on group 1 only");
  }
  x.type(colvarvalue::type_scalar);
}
示例#10
0
colvar::cartesian::cartesian(std::string const &conf)
  : cvc(conf)
{
  b_inverse_gradients = false;
  b_Jacobian_derivative = false;
  function_type = "cartesian";

  parse_group(conf, "atoms", atoms);
  atom_groups.push_back(&atoms);

  bool use_x, use_y, use_z;
  get_keyval(conf, "useX", use_x, true);
  get_keyval(conf, "useY", use_y, true);
  get_keyval(conf, "useZ", use_z, true);

  axes.clear();
  if (use_x) axes.push_back(0);
  if (use_y) axes.push_back(1);
  if (use_z) axes.push_back(2);

  if (axes.size() == 0) {
    cvm::error("Error: a \"cartesian\" component was defined with all three axes disabled.\n");
  }

  x.type(colvarvalue::type_vector);
  x.vector1d_value.resize(atoms.size() * axes.size());
}
示例#11
0
static void
parse_pad (xmlNodePtr node, InputPadGroup **pgroup)
{
    xmlNodePtr current;
    gboolean has_pad = FALSE;

    for (current = node; current; current = current->next) {
        if (current->type == XML_ELEMENT_NODE &&
            !g_strcmp0 ((char *) current->name, "group")) {
            if (current->children) {
                *pgroup = g_new0 (InputPadGroup, 1);
                (*pgroup)->priv = g_new0 (InputPadGroupPrivate, 1);
                parse_group (current->children, pgroup);
                has_pad = TRUE;
                pgroup = &((*pgroup)->next);
            } else {
                g_error ("tag %s does not have child tags in the file %s",
                         (char *) current->name,
                         xml_file);
            }
        }
    }

    if (!has_pad) {
        g_error ("tag %s does not find \"group\" tag in file %s",
                 node->parent ? node->parent->name ? (char *) node->parent->name : "(null)" : "(null)",
                 xml_file);
    }
}
colvar::inertia::inertia (std::string const &conf)
  : cvc (conf)
{
  function_type = "inertia";
  parse_group (conf, "atoms", atoms);
  atom_groups.push_back (&atoms);
  x.type (colvarvalue::type_scalar);
}
colvar::angle::angle (std::string const &conf)
  : cvc (conf)
{
  function_type = "angle";
  b_inverse_gradients = true;
  b_Jacobian_derivative = true;
  parse_group (conf, "group1", group1);
  parse_group (conf, "group2", group2);
  parse_group (conf, "group3", group3);
  atom_groups.push_back (&group1);
  atom_groups.push_back (&group2);
  atom_groups.push_back (&group3);
  if (get_keyval (conf, "oneSiteSystemForce", b_1site_force, false)) {
    cvm::log ("Computing system force on group 1 only");
  }
  x.type (colvarvalue::type_scalar);
}
示例#14
0
static GPInstructLesson *
parse_lesson (xmlNode *node)
{
	GPInstructLesson *lesson = gpinstruct_lesson_new ();

	xmlNode *current_node;
	xmlChar *temp;

	temp = xmlGetProp (node, BAD_CAST "title");
	if (temp)
	{
		gpinstruct_lesson_set_title (lesson, (gchar*) temp);
		xmlFree (temp);
	}

	temp = xmlGetProp (node, BAD_CAST "single-score");
	if (temp)
	{
		gpinstruct_lesson_set_single_score (lesson, GCHAR_TO_GBOOLEAN ((gchar*) temp));
		xmlFree (temp);
	}

	for (current_node = node->children;
	     current_node != NULL;
	     current_node = current_node->next)
	{
		if (current_node->type == XML_ELEMENT_NODE)
		{
			if (xmlStrEqual (current_node->name, BAD_CAST "test-multi-choice"))
				gpinstruct_lesson_add_lesson_element (lesson,
				                                      GPINSTRUCT_LESSON_ELEMENT (parse_multi_choice_test (current_node)));
			else if (xmlStrEqual (current_node->name, BAD_CAST "test-word-pool"))
				gpinstruct_lesson_add_lesson_element (lesson,
				                                      GPINSTRUCT_LESSON_ELEMENT (parse_word_pool_test (current_node)));
			else if (xmlStrEqual (current_node->name, BAD_CAST "test-order"))
				gpinstruct_lesson_add_lesson_element (lesson,
				                                      GPINSTRUCT_LESSON_ELEMENT (parse_order_test (current_node)));
			else if (xmlStrEqual (current_node->name, BAD_CAST "test-text"))
				gpinstruct_lesson_add_lesson_element (lesson,
				                                      GPINSTRUCT_LESSON_ELEMENT (parse_text_test (current_node)));
			else if (xmlStrEqual (current_node->name, BAD_CAST "test-scrambled"))
				gpinstruct_lesson_add_lesson_element (lesson,
				                                      GPINSTRUCT_LESSON_ELEMENT (parse_scrambled_test (current_node)));
			else if (xmlStrEqual (current_node->name, BAD_CAST "discussion"))
				gpinstruct_lesson_add_lesson_element (lesson,
				                                      GPINSTRUCT_LESSON_ELEMENT (parse_discussion (current_node)));
			else if (xmlStrEqual (current_node->name, BAD_CAST "reading"))
				gpinstruct_lesson_add_lesson_element (lesson,
				                                      GPINSTRUCT_LESSON_ELEMENT (parse_reading (current_node)));
			else if (xmlStrEqual (current_node->name, BAD_CAST "group"))
				gpinstruct_lesson_add_lesson_element (lesson,
				                                      GPINSTRUCT_LESSON_ELEMENT (parse_group (current_node)));
		}
	}

	return lesson;
}
colvar::gyration::gyration (std::string const &conf)
  : cvc (conf)
{
  function_type = "gyration";
  b_inverse_gradients = true;
  b_Jacobian_derivative = true;
  parse_group (conf, "atoms", atoms);
  atom_groups.push_back (&atoms);
  x.type (colvarvalue::type_scalar);
}
示例#16
0
colvar::distance::distance(std::string const &conf)
  : cvc(conf)
{
  function_type = "distance";
  provide(f_cvc_inv_gradient);
  provide(f_cvc_Jacobian);
  enable(f_cvc_com_based);

  group1 = parse_group(conf, "group1");
  group2 = parse_group(conf, "group2");

  if (get_keyval(conf, "forceNoPBC", b_no_PBC, false)) {
    cvm::log("Computing distance using absolute positions (not minimal-image)");
  }

  init_total_force_params(conf);

  x.type(colvarvalue::type_scalar);
}
示例#17
0
colvar::dihedral::dihedral(std::string const &conf)
  : cvc(conf)
{
  function_type = "dihedral";
  period = 360.0;
  b_periodic = true;
  provide(f_cvc_inv_gradient);
  provide(f_cvc_Jacobian);
  provide(f_cvc_com_based);

  if (get_keyval(conf, "oneSiteSystemForce", b_1site_force, false)) {
    cvm::log("Computing system force on group 1 only");
  }
  group1 = parse_group(conf, "group1");
  group2 = parse_group(conf, "group2");
  group3 = parse_group(conf, "group3");
  group4 = parse_group(conf, "group4");

  x.type(colvarvalue::type_scalar);
}
示例#18
0
colvar::distance_pairs::distance_pairs(std::string const &conf)
  : cvc(conf)
{
  function_type = "distance_pairs";
  b_inverse_gradients = false;
  b_Jacobian_derivative = false;

  if (get_keyval(conf, "forceNoPBC", b_no_PBC, false)) {
    cvm::log("Computing distance using absolute positions (not minimal-image)");
  }

  parse_group(conf, "group1", group1);
  atom_groups.push_back(&group1);

  parse_group(conf, "group2", group2);
  atom_groups.push_back(&group2);

  x.type(colvarvalue::type_vector);
  x.vector1d_value.resize(group1.size() * group2.size());
}
colvar::distance::distance (std::string const &conf, bool twogroups)
  : cvc (conf)
{
  function_type = "distance";
  b_inverse_gradients = true;
  b_Jacobian_derivative = true;
  if (get_keyval (conf, "forceNoPBC", b_no_PBC, false)) {
    cvm::log ("Computing distance using absolute positions (not minimal-image)");
  }
  if (twogroups && get_keyval (conf, "oneSiteSystemForce", b_1site_force, false)) {
    cvm::log ("Computing system force on group 1 only");
  }
  parse_group (conf, "group1", group1);
  atom_groups.push_back (&group1);
  if (twogroups) {
    parse_group (conf, "group2", group2);
    atom_groups.push_back (&group2);
  }
  x.type (colvarvalue::type_scalar);
}
示例#20
0
文件: wopr.c 项目: scumola/GalaxyNG
int
WOPR_parse_scenario( FILE *scenario, game *aGame )
{
    char *read;
    int reading;
    player *aPlayer = NULL;

    for ( read = getLine( scenario );
          read != NULL; read = getLine( scenario ) ) {
        char *key;


        key = getstr( lineBuffer );
        if ( noCaseStrcmp( key, "PLAYER" ) == 0 ) {
            char *name;
            name = getstr( NULL );
            if ( name[0] != '\0' ) {
                aPlayer = WOPR_addPlayer( aGame, name );
                reading = READING_NONE;
            } else {
                fprintf( stderr, "No name specified\n" );
                return FALSE;
            }
        } else if ( noCaseStrcmp( key, "GROUPS" ) == 0 ) {
            reading = READING_GROUPS;
        } else if ( noCaseStrcmp( key, "TYPES" ) == 0 ) {
            reading = READING_TYPES;
        } else if ( key[0] == '\0' ) {
            /* It was a remark, skip it */
        } else {
            int result;
            switch ( reading ) {
            case READING_GROUPS:
                assert( aPlayer );
                result = parse_group( aGame, aPlayer );
                break;
            case READING_TYPES:
                assert( aPlayer );
                result = WOPR_parse_type( aGame, aPlayer );
                break;
            }
            if ( !result ) {
                return FALSE;
            }
        }
    }
    return TRUE;
}
示例#21
0
colvar::gyration::gyration(std::string const &conf)
  : cvc(conf)
{
  function_type = "gyration";
  provide(f_cvc_inv_gradient);
  provide(f_cvc_Jacobian);
  atoms = parse_group(conf, "atoms");

  if (atoms->b_user_defined_fit) {
    cvm::log("WARNING: explicit fitting parameters were provided for atom group \"atoms\".");
  } else {
    atoms->b_center = true;
    atoms->ref_pos.assign(1, cvm::atom_pos(0.0, 0.0, 0.0));
  }

  x.type(colvarvalue::type_scalar);
}
示例#22
0
colvar::gyration::gyration (std::string const &conf)
  : cvc (conf)
{
  function_type = "gyration";
  b_inverse_gradients = true;
  b_Jacobian_derivative = true;
  parse_group (conf, "atoms", atoms);
  atom_groups.push_back (&atoms);

  if (atoms.b_user_defined_fit) {
    cvm::log ("WARNING: explicit fitting parameters were provided for atom group \"atoms\".");
  } else {
    atoms.b_center = true;
    atoms.ref_pos.assign (1, cvm::rvector (0.0, 0.0, 0.0));
  }

  x.type (colvarvalue::type_scalar);
}
示例#23
0
/*
 * This routine replaces user/group name with numeric id.
 */
static char *
resolve_ids(char *rule)
{
	id_t id;
	const char *subject, *textid, *rest;
	char *resolved;

	subject = strsep(&rule, ":");
	textid = strsep(&rule, ":");
	if (textid == NULL)
		errx(1, "error in rule specification -- no subject");
	if (rule != NULL)
		rest = rule;
	else
		rest = "";

	if (strcasecmp(subject, "u") == 0)
		subject = "user";
	else if (strcasecmp(subject, "g") == 0)
		subject = "group";
	else if (strcasecmp(subject, "p") == 0)
		subject = "process";
	else if (strcasecmp(subject, "l") == 0 ||
	    strcasecmp(subject, "c") == 0 ||
	    strcasecmp(subject, "class") == 0)
		subject = "loginclass";
	else if (strcasecmp(subject, "j") == 0)
		subject = "jail";

	if (strcasecmp(subject, "user") == 0 && strlen(textid) > 0) {
		id = parse_user(textid);
		asprintf(&resolved, "%s:%d:%s", subject, (int)id, rest);
	} else if (strcasecmp(subject, "group") == 0 && strlen(textid) > 0) {
		id = parse_group(textid);
		asprintf(&resolved, "%s:%d:%s", subject, (int)id, rest);
	} else
		asprintf(&resolved, "%s:%s:%s", subject, textid, rest);

	if (resolved == NULL)
		err(1, "asprintf");

	return (resolved);
}
示例#24
0
static char *
humanize_ids(char *rule)
{
	id_t id;
	struct passwd *pwd;
	struct group *grp;
	const char *subject, *textid, *rest;
	char *humanized;

	subject = strsep(&rule, ":");
	textid = strsep(&rule, ":");
	if (textid == NULL)
		errx(1, "rule passed from the kernel didn't contain subject");
	if (rule != NULL)
		rest = rule;
	else
		rest = "";

	/* Replace numerical user and group ids with names. */
	if (strcasecmp(subject, "user") == 0) {
		id = parse_user(textid);
		pwd = getpwuid(id);
		if (pwd != NULL)
			textid = pwd->pw_name;
	} else if (strcasecmp(subject, "group") == 0) {
		id = parse_group(textid);
		grp = getgrgid(id);
		if (grp != NULL)
			textid = grp->gr_name;
	}

	asprintf(&humanized, "%s:%s:%s", subject, textid, rest);

	if (humanized == NULL)
		err(1, "asprintf");

	return (humanized);
}
示例#25
0
文件: fifo.c 项目: CESNET/torque
/*
 *
 * schedinit - initialize conf struct and parse conf files
 *
 *   argc - passed in from main
 *   argv - passed in from main
 *
 * Returns Success/Failure
 *
 *
 */
int schedinit(int argc, char *argv[])
  {
  init_config();
  parse_config(CONFIG_FILE);
  parse_holidays(HOLIDAYS_FILE);

  time(&(cstat.current_time));

  if (is_prime_time())
    init_prime_time();
  else
    init_non_prime_time();

  parse_ded_file(DEDTIME_FILE);

  /* preload the static members to the fairshare tree */
  preload_tree();

  parse_group(RESGROUP_FILE);

  calc_fair_share_perc(conf.group_root -> child, UNSPECIFIED);

  if (conf.prime_fs || conf.non_prime_fs)
    {
    read_usage();

    /*
     * initialize the last_decay to the current time, since we do not know when
     * the last decay happened
     */
    last_sync = last_decay = cstat.current_time;
    }

  token_acct_open((char *)0);

  return 0;
  }
colvar::eigenvector::eigenvector (std::string const &conf)
  : cvc (conf)
{
  b_inverse_gradients = true;
  b_Jacobian_derivative = true;
  function_type = "eigenvector";
  x.type (colvarvalue::type_scalar);

  parse_group (conf, "atoms", atoms);
  atom_groups.push_back (&atoms);

  if (atoms.b_rotate) {
    cvm::fatal_error ("Error: rotateReference should be disabled:"
        "eigenvector component will set it internally.");
  }

  if (get_keyval (conf, "refPositions", ref_pos, ref_pos)) {
    cvm::log ("Using reference positions from input file.\n");
    if (ref_pos.size() != atoms.size()) {
      cvm::fatal_error ("Error: reference positions do not "
                        "match the number of requested atoms.\n");
    }
  }

  {
    std::string file_name;
    if (get_keyval (conf, "refPositionsFile", file_name)) {

      std::string file_col;
      double file_col_value;
      if (get_keyval (conf, "refPositionsCol", file_col, std::string (""))) {
        // use PDB flags if column is provided
        bool found = get_keyval (conf, "refPositionsColValue", file_col_value, 0.0);
        if (found && !file_col_value)
          cvm::fatal_error ("Error: refPositionsColValue, "
                            "if provided, must be non-zero.\n");
      } else {
        // if not, use atom indices
        atoms.create_sorted_ids();
      }

      ref_pos.resize (atoms.size());
      cvm::load_coords (file_name.c_str(), ref_pos, atoms.sorted_ids, file_col, file_col_value);
    }
  }

  // Set mobile frame of reference for atom group
  atoms.b_center = true;
  atoms.b_rotate = true;
  atoms.ref_pos = ref_pos;

  // now load the eigenvector
  if (get_keyval (conf, "vector", eigenvec, eigenvec)) {
    cvm::log ("Using vector components from input file.\n");
    if (eigenvec.size() != atoms.size()) {
      cvm::fatal_error ("Error: vector components do not "
                        "match the number of requested atoms.\n");
    }
  }

  {
    std::string file_name;
    if (get_keyval (conf, "vectorFile", file_name)) {

      std::string file_col;
      if (!get_keyval (conf, "vectorCol", file_col, std::string (""))) {
        cvm::fatal_error ("Error: parameter vectorCol is required if vectorFile is set.\n");
      }

      double file_col_value;
      bool found = get_keyval (conf, "vectorColValue", file_col_value, 0.0);
      if (found && !file_col_value)
        cvm::fatal_error ("Error: eigenvectorColValue, "
                          "if provided, must be non-zero.\n");

      eigenvec.resize (atoms.size());
      cvm::load_coords (file_name.c_str(), eigenvec, atoms.sorted_ids, file_col, file_col_value);
    }
  }

  if (!ref_pos.size() || !eigenvec.size()) {
    cvm::fatal_error ("Error: both reference coordinates"
                      "and eigenvector must be defined.\n");
  }

  cvm::rvector center (0.0, 0.0, 0.0);
  eigenvec_invnorm2 = 0.0;

  for (size_t i = 0; i < atoms.size(); i++) {
    center += eigenvec[i];
  }

  cvm::log ("Subtracting sum of eigenvector components: " + cvm::to_str (center) + "\n");

  for (size_t i = 0; i < atoms.size(); i++) {
    eigenvec[i] = eigenvec[i] - center;
    eigenvec_invnorm2 += eigenvec[i].norm2();
  }
  eigenvec_invnorm2 = 1.0 / eigenvec_invnorm2;

  // request derivatives of optimal rotation wrt 2nd group
  // for Jacobian
  atoms.rot.request_group1_gradients(atoms.size());
  atoms.rot.request_group2_gradients(atoms.size());
}
示例#27
0
group_t*
cfg_load(FILE *fp) {
    char line[MAXLINELEN];
    group_t *head = NULL, *curr = NULL;

    if (fp == NULL)
        return NULL;

    rewind(fp);

    lineno = 0;
    while(fgets(line, sizeof(line), fp)) {
        char *p = line;
	++lineno;
        /* Skip any whitespace at start of line */
        skip_whitespace(&p);
        /* Skip line if only whitespace */
        if (!*p) continue;

        switch(*p) {
            case '[':
                /* parse config group */
                {
                    group_t *newgrp = parse_group(p);
                    if (curr == NULL) {
                        head = curr = newgrp;
                    } else {
                        curr->next = newgrp;
                        curr = newgrp;
                    }
                }
                break;
            case '{':
                /* parse list item */
                {
                    variable_t *var = parse_listitem(p,head);
                    if (curr != NULL) {
                        add_var_to_group(curr, var);
                    } else {
                        fprintf(stderr, "%s:%d: Found list item but no current group!\n", __func__, lineno);
                    }
                }
                break;
            default:
                /* check for simple key/value */
                if (isalpha(*p)) {
                    variable_t *var = parse_keyvalue(&p,head);
                    if (curr != NULL) {
                        add_var_to_group(curr, var);
                    } else {
                        fprintf(stderr, "%s:%d: Found variable but no current group!\n", __func__, lineno);
                    }
                } else {
                    fprintf(stderr, "%s:%d: unknown line: %s\n", __func__, lineno, line);
                }
                break;
        }
    }

    //fclose(fp);

    return head;
}
示例#28
0
colvar::rmsd::rmsd(std::string const &conf)
  : cvc(conf)
{
  provide(f_cvc_inv_gradient);
  function_type = "rmsd";
  x.type(colvarvalue::type_scalar);

  atoms = parse_group(conf, "atoms");

  if (!atoms || atoms->size() == 0) {
    cvm::error("Error: \"atoms\" must contain at least 1 atom to compute RMSD.");
    return;
  }

  bool b_Jacobian_derivative = true;
  if (atoms->fitting_group != NULL && b_Jacobian_derivative) {
    cvm::log("The option \"refPositionsGroup\" (alternative group for fitting) was enabled: "
              "Jacobian derivatives of the RMSD will not be calculated.\n");
    b_Jacobian_derivative = false;
  }
  if (b_Jacobian_derivative) provide(f_cvc_Jacobian);

  // the following is a simplified version of the corresponding atom group options;
  // we need this because the reference coordinates defined inside the atom group
  // may be used only for fitting, and even more so if fitting_group is used
  if (get_keyval(conf, "refPositions", ref_pos, ref_pos)) {
    cvm::log("Using reference positions from configuration file to calculate the variable.\n");
    if (ref_pos.size() != atoms->size()) {
      cvm::error("Error: the number of reference positions provided ("+
                  cvm::to_str(ref_pos.size())+
                  ") does not match the number of atoms of group \"atoms\" ("+
                  cvm::to_str(atoms->size())+").\n");
      return;
    }
  }
  {
    std::string ref_pos_file;
    if (get_keyval(conf, "refPositionsFile", ref_pos_file, std::string(""))) {

      if (ref_pos.size()) {
        cvm::error("Error: cannot specify \"refPositionsFile\" and "
                          "\"refPositions\" at the same time.\n");
        return;
      }

      std::string ref_pos_col;
      double ref_pos_col_value=0.0;

      if (get_keyval(conf, "refPositionsCol", ref_pos_col, std::string(""))) {
        // if provided, use PDB column to select coordinates
        bool found = get_keyval(conf, "refPositionsColValue", ref_pos_col_value, 0.0);
        if (found && ref_pos_col_value==0.0) {
          cvm::error("Error: refPositionsColValue, "
                     "if provided, must be non-zero.\n");
          return;
        }
      } else {
        // if not, rely on existing atom indices for the group
        atoms->create_sorted_ids();
        ref_pos.resize(atoms->size());
      }

      cvm::load_coords(ref_pos_file.c_str(), ref_pos, atoms->sorted_ids,
                        ref_pos_col, ref_pos_col_value);
    }
  }

  if (ref_pos.size() != atoms->size()) {
    cvm::error("Error: found " + cvm::to_str(ref_pos.size()) +
                    " reference positions; expected " + cvm::to_str(atoms->size()));
    return;
  }

  if (atoms->b_user_defined_fit) {
    cvm::log("WARNING: explicit fitting parameters were provided for atom group \"atoms\".");
  } else {
    // Default: fit everything
    cvm::log("Enabling \"centerReference\" and \"rotateReference\", to minimize RMSD before calculating it as a variable: "
              "if this is not the desired behavior, disable them explicitly within the \"atoms\" block.\n");
    atoms->b_center = true;
    atoms->b_rotate = true;
    // default case: reference positions for calculating the rmsd are also those used
    // for fitting
    atoms->ref_pos = ref_pos;
    atoms->center_ref_pos();

    cvm::log("This is a standard minimum RMSD, derivatives of the optimal rotation "
              "will not be computed as they cancel out in the gradients.");
    atoms->disable(f_ag_fit_gradients);

    // request the calculation of the derivatives of the rotation defined by the atom group
    atoms->rot.request_group1_gradients(atoms->size());
    // request derivatives of optimal rotation wrt reference coordinates for Jacobian:
    // this is only required for ABF, but we do both groups here for better caching
    atoms->rot.request_group2_gradients(atoms->size());
  }
}
示例#29
0
文件: fifo.c 项目: CESNET/torque
int schedule(

  int cmd,
  int sd)

  {
  switch (cmd)
    {

    case SCH_ERROR:

    case SCH_SCHEDULE_NULL:

    case SCH_RULESET:

    case SCH_SCHEDULE_RECYC:

      /* ignore and end cycle */

      break;

    case SCH_SCHEDULE_NEW:

    case SCH_SCHEDULE_TERM:

    case SCH_SCHEDULE_FIRST:

    case SCH_SCHEDULE_CMD:

    case SCH_SCHEDULE_TIME:

      return(scheduling_cycle(sd));

      /*NOTREACHED*/

      break;

    case SCH_CONFIGURE:

      if (conf.prime_fs || conf.non_prime_fs)
        write_usage();

      reinit_config();

      parse_config(CONFIG_FILE);

      parse_holidays(HOLIDAYS_FILE);

      parse_ded_file(DEDTIME_FILE);

      preload_tree();

      parse_group(RESGROUP_FILE);

      calc_fair_share_perc(conf.group_root -> child, UNSPECIFIED);

      if (conf.prime_fs || conf.non_prime_fs)
        read_usage();

      break;

    case SCH_QUIT:
      if (conf.prime_fs || conf.non_prime_fs)
        write_usage();

      return 1;  /* have the scheduler exit nicely */

    default:
      return 0;
    }

  return(0);
  }  /* END schedule() */
示例#30
0
colvar::eigenvector::eigenvector(std::string const &conf)
  : cvc(conf)
{
  provide(f_cvc_inv_gradient);
  provide(f_cvc_Jacobian);
  function_type = "eigenvector";
  x.type(colvarvalue::type_scalar);

  atoms = parse_group(conf, "atoms");

  {
    bool const b_inline = get_keyval(conf, "refPositions", ref_pos, ref_pos);

    if (b_inline) {
      cvm::log("Using reference positions from input file.\n");
      if (ref_pos.size() != atoms->size()) {
        cvm::error("Error: reference positions do not "
                   "match the number of requested atoms.\n");
        return;
      }
    }

    std::string file_name;
    if (get_keyval(conf, "refPositionsFile", file_name)) {

      if (b_inline) {
        cvm::error("Error: refPositions and refPositionsFile cannot be specified at the same time.\n");
        return;
      }

      std::string file_col;
      double file_col_value=0.0;
      if (get_keyval(conf, "refPositionsCol", file_col, std::string(""))) {
        // use PDB flags if column is provided
        bool found = get_keyval(conf, "refPositionsColValue", file_col_value, 0.0);
        if (found && file_col_value==0.0) {
          cvm::error("Error: refPositionsColValue, "
                            "if provided, must be non-zero.\n");
          return;
        }
      } else {
        // if not, use atom indices
        atoms->create_sorted_ids();
      }

      ref_pos.resize(atoms->size());
      cvm::load_coords(file_name.c_str(), ref_pos, atoms->sorted_ids, file_col, file_col_value);
    }
  }

  if (ref_pos.size() == 0) {
    cvm::error("Error: reference positions were not provided.\n", INPUT_ERROR);
    return;
  }

  if (ref_pos.size() != atoms->size()) {
    cvm::error("Error: reference positions do not "
               "match the number of requested atoms.\n", INPUT_ERROR);
    return;
  }

  // save for later the geometric center of the provided positions (may not be the origin)
  cvm::rvector ref_pos_center(0.0, 0.0, 0.0);
  for (size_t i = 0; i < atoms->size(); i++) {
    ref_pos_center += ref_pos[i];
  }
  ref_pos_center *= 1.0 / atoms->size();

  if (atoms->b_user_defined_fit) {
    cvm::log("WARNING: explicit fitting parameters were provided for atom group \"atoms\".\n");
  } else {
    // default: fit everything
    cvm::log("Enabling \"centerReference\" and \"rotateReference\", to minimize RMSD before calculating the vector projection: "
              "if this is not the desired behavior, disable them explicitly within the \"atoms\" block.\n");
    atoms->b_center = true;
    atoms->b_rotate = true;
    atoms->ref_pos = ref_pos;
    atoms->center_ref_pos();
    atoms->disable(f_ag_fit_gradients); // cancel out if group is fitted on itself
                                        // and cvc is translationally invariant

    // request the calculation of the derivatives of the rotation defined by the atom group
    atoms->rot.request_group1_gradients(atoms->size());
    // request derivatives of optimal rotation wrt reference coordinates for Jacobian:
    // this is only required for ABF, but we do both groups here for better caching
    atoms->rot.request_group2_gradients(atoms->size());
  }

  {
    bool const b_inline = get_keyval(conf, "vector", eigenvec, eigenvec);
    // now load the eigenvector
    if (b_inline) {
      cvm::log("Using vector components from input file.\n");
      if (eigenvec.size() != atoms->size()) {
        cvm::error("Error: vector components do not "
                          "match the number of requested atoms->\n");
        return;
      }
    }

    std::string file_name;
    if (get_keyval(conf, "vectorFile", file_name)) {

      if (b_inline) {
        cvm::error("Error: vector and vectorFile cannot be specified at the same time.\n");
        return;
      }

      std::string file_col;
      double file_col_value=0.0;
      if (get_keyval(conf, "vectorCol", file_col, std::string(""))) {
        // use PDB flags if column is provided
        bool found = get_keyval(conf, "vectorColValue", file_col_value, 0.0);
        if (found && file_col_value==0.0) {
          cvm::error("Error: vectorColValue, if provided, must be non-zero.\n");
          return;
        }
      } else {
        // if not, use atom indices
        atoms->create_sorted_ids();
      }

      eigenvec.resize(atoms->size());
      cvm::load_coords(file_name.c_str(), eigenvec, atoms->sorted_ids, file_col, file_col_value);
    }
  }

  if (!ref_pos.size() || !eigenvec.size()) {
    cvm::error("Error: both reference coordinates"
                      "and eigenvector must be defined.\n");
    return;
  }

  cvm::atom_pos eig_center(0.0, 0.0, 0.0);
  for (size_t eil = 0; eil < atoms->size(); eil++) {
    eig_center += eigenvec[eil];
  }
  eig_center *= 1.0 / atoms->size();
  cvm::log("Geometric center of the provided vector: "+cvm::to_str(eig_center)+"\n");

  bool b_difference_vector = false;
  get_keyval(conf, "differenceVector", b_difference_vector, false);

  if (b_difference_vector) {

    if (atoms->b_center) {
      // both sets should be centered on the origin for fitting
      for (size_t i = 0; i < atoms->size(); i++) {
        eigenvec[i] -= eig_center;
        ref_pos[i]  -= ref_pos_center;
      }
    }
    if (atoms->b_rotate) {
      atoms->rot.calc_optimal_rotation(eigenvec, ref_pos);
      for (size_t i = 0; i < atoms->size(); i++) {
        eigenvec[i] = atoms->rot.rotate(eigenvec[i]);
      }
    }
    cvm::log("\"differenceVector\" is on: subtracting the reference positions from the provided vector: v = v - x0.\n");
    for (size_t i = 0; i < atoms->size(); i++) {
      eigenvec[i] -= ref_pos[i];
    }
    if (atoms->b_center) {
      // bring back the ref positions to where they were
      for (size_t i = 0; i < atoms->size(); i++) {
        ref_pos[i] += ref_pos_center;
      }
    }

  } else {
    cvm::log("Centering the provided vector to zero.\n");
    for (size_t i = 0; i < atoms->size(); i++) {
      eigenvec[i] -= eig_center;
    }
  }

  // cvm::log("The first three components(v1x, v1y, v1z) of the resulting vector are: "+cvm::to_str (eigenvec[0])+".\n");

  // for inverse gradients
  eigenvec_invnorm2 = 0.0;
  for (size_t ein = 0; ein < atoms->size(); ein++) {
    eigenvec_invnorm2 += eigenvec[ein].norm2();
  }
  eigenvec_invnorm2 = 1.0 / eigenvec_invnorm2;

  if (b_difference_vector) {
    cvm::log("\"differenceVector\" is on: normalizing the vector.\n");
    for (size_t i = 0; i < atoms->size(); i++) {
      eigenvec[i] *= eigenvec_invnorm2;
    }
  } else {
    cvm::log("The norm of the vector is |v| = "+cvm::to_str(eigenvec_invnorm2)+".\n");
  }
}