Example #1
0
 string location_of(atom atom)
 {
  int path_id=literal_id(atom.path());
  int line_id=literal_id(atom.line().trim());
  
  return concat("location",pack(path_id,line_id,atom.number()).join(",").parens());
 }
Example #2
0
 int literal_id(atom value)
 {
  //string
  
  if(value.is_string())
   return _literals.index(value.get());
  
  //literal
  
  return literal_id(value.get());
 }
Example #3
0
wrl::atom::atom(const atom& that)
{
    param_map::const_iterator i;

    // Copy that atom.

    *this = that;

    // Duplicate GL state.

    if (that.fill) fill = new ogl::unit(*that.fill);
    if (that.line) line = new ogl::unit(*that.line);

    // Duplicate ODE state.

    if ((edit_geom = that.new_edit_geom(0)))
    {
        dGeomSetData     (edit_geom, this);
        bGeomSetTransform(edit_geom, current_M);
    }

    // Flush and clone each parameter separately.

    params.clear();

    for (i = that.params.begin(); i != that.params.end(); ++i)
        params[i->first] = new param(*i->second);
}
Example #4
0
void test_single_cas(size_t id, size_t nrun) {
    size_t dummy;
    for (size_t i = 0; i < nrun; i++) {
        lock_instr_test.compare_exchange_weak(dummy,
                                              dummy+1,
					      std::memory_order_relaxed,
                                              std::memory_order_relaxed);
    }
}
typename basic_otp_mailbox_registry<Alloc, Mutex>::mailbox_ptr
basic_otp_mailbox_registry<Alloc, Mutex>::create_mailbox(
    const atom& a_name, boost::asio::io_service* a_svc)
{
    lock_guard<Mutex> guard(m_lock);
    if (!a_name.empty()) {
        typename std::map<atom, mailbox_ptr>::iterator it = m_by_name.find(a_name);
        if (it != m_by_name.end())
            return it->second;   // Already registered!
    }

    epid<Alloc> l_pid = m_owner_node.create_pid();
    mailbox_ptr mbox = new mailbox_type(m_owner_node, l_pid, a_name, a_svc);
    if (!a_name.empty())
        m_by_name.insert(std::pair<atom, mailbox_ptr>(a_name, mbox));
    m_by_pid.insert(std::pair<epid<Alloc>, mailbox_ptr>(l_pid, mbox));
    return mbox;
}
Example #6
0
void test_many_cas(size_t id, size_t nrun) {
    size_t dummy;
    for (size_t i = 0; i < nrun; i++) {
        while (!lock_instr_test.compare_exchange_weak(dummy,
                                                      dummy+1,
                                                      std::memory_order_relaxed,
                                                      std::memory_order_relaxed))
        {}
    }
}
    void timer_reconnect(const boost::system::error_code& ec) {
        if (ec == boost::asio::error::operation_aborted)
            return;     // timer reset

        if (verbose() >= VERBOSE_TRACE)
            std::cerr << "basic_otp_connection::timer_reconnect: " << ec.message() << std::endl;

        m_transport = connection_type::create(
                          m_io_service, this, m_node->nodename().to_string(),
                          m_remote_nodename.to_string(), m_cookie, m_alloc);
    }
bool basic_otp_mailbox_registry<Alloc, Mutex>::unregister(const atom& a_name)
{
    if (!a_name.empty())
        return false;
    lock_guard<Mutex> guard(m_lock);
    typename std::map<atom, mailbox_ptr>::iterator it = m_by_name.find(a_name);
    if (it == m_by_name.end())
        return;
    it->second.name("");
    m_by_name.erase(it);
}
Example #9
0
 string value_of(atom atom)
 {
  string type=atom.type();
  string value=atom.get();
  
  if(atom.is_number())
  {
   //number
  
   if(value.is_integer())
    type="integer";
   else
   {
    check(value.is_real());

    type="real";
   }
  }
  else if(atom.is_string())
  {
   //string

   type="literal";
   value=stringify(literal_id(atom));
  }
  else if(atom.is_identifier())
  {
   //identifier
   
   value=_identifiers.index(literal_id(atom)).string_();
  }
  else
  {
   //raw

   type="literal";
   value=stringify(literal_id(atom));
  }
   
  return concat(type,value.parens());
 }
bool basic_otp_mailbox_registry<Alloc, Mutex>::add(const atom& a_name, mailbox_ptr a_mbox)
{
    if (a_name.empty())
        throw err_bad_argument("Empty registering name!");
    if (!a_mbox->name().empty())
        throw err_bad_argument("Mailbox already registered as", a_mbox->name());
    lock_guard<Mutex> guard(m_lock);
    if (m_by_name.find(a_name) != m_by_name.end())
        return false;
    m_by_name.insert(std::pair<atom, mailbox_ptr>(a_name, a_mbox));
    a_mbox->name(a_name);
    return true;
}
Example #11
0
// Verify data encoding
void check(atom test, atom::type_t type, atom::enc_t enc, size_t size)
{
    atom::type_t type_found;
    atom::enc_t enc_found;
    byte_vector test_bytes = test.encode_vector();
    atom copy;

    // Dump
    printf("Atom: ");
    test.print();

    // What's in the atom?
    type_found = test.get_type();
    printf("\nData Type: %s\n", atom_type_to_string(type_found));
    if (type != type_found)
    {
        printf("*** Failed (expected %s) ***\n", atom_type_to_string(type));
        exit(1);
    }

    // How is it encoded?
    enc_found = test.get_enc();
    printf("Encoding: %s\n", atom_enc_to_string(enc_found));
    if (enc != enc_found)
    {
        printf("*** Failed (expected %s) ***\n", atom_enc_to_string(enc));
        exit(1);
    }

    // Debug
    dump(test_bytes);

    // Check total size
    if (test.get_header_size() + size != test_bytes.size())
    {
        printf("*** Failed (expected %u bytes) ***\n",
               (unsigned int)(test.get_header_size() + size));
        exit(1);
    }

    // Reconstruct atom
    printf("Testing reconstructed copy ...\n");
    copy.decode_vector(test_bytes);
    if (test != copy)
    {
        printf("*** Failed (decoded object differs) ***\n");
        exit(1);
    }

    // Bump the counter
    test_count++;
}
 basic_otp_connection(
     connect_completion_handler h,
     boost::asio::io_service& a_svc,
     basic_otp_node<Alloc,Mutex>* a_node, const atom& a_remote_node,
     const std::string& a_cookie, int a_reconnect_secs = 0,
     const Alloc& a_alloc = Alloc())
     : m_io_service(a_svc)
     , m_node(a_node)
     , m_remote_nodename(a_remote_node)
     , m_cookie(a_cookie)
     , m_alloc(a_alloc)
     , m_connected(false)
     , m_reconnect_timer(m_io_service)
     , m_reconnect_secs(a_reconnect_secs)
     , m_abort(false)
 {
     BOOST_ASSERT(a_node != NULL);
     m_on_connect_status = h;
     m_transport = connection_type::create(
                       m_io_service, this, a_node->nodename().to_string(),
                       a_remote_node.to_string(), a_cookie, a_alloc);
 }
Example #13
0
void test_single_add(size_t id, size_t nrun) {
    for (size_t i = 0; i < nrun; i++) {
        lock_instr_test.fetch_add(1, std::memory_order_relaxed);
    }
}
Example #14
0
//! Returns true if the current atom is covalently bonded to a given atom.
bool atom::is_neighbor(const atom& a) const
{
	assert(this != &a);
	const double r = 1.1 * (covalent_radius() + a.covalent_radius());
	return distance_sqr(coord, a.coord) < r * r;
}
Example #15
0
 size_t                  length()        const { return m_name.length(); }
Example #16
0
 const string_t&         str()           const { return m_name.to_string(); }
Example #17
0
 const char*             c_str()         const { return m_name.c_str(); }
Example #18
0
	/// Returns true if the current atom is covalently bonded to a given atom.
	bool has_covalent_bond(const atom& a) const
	{
		const float s = covalent_radius() + a.covalent_radius();
		return distance_sqr(coord, a.coord) < s * s;
	}
Example #19
0
 port(const atom& node, const int id, const int creation, const Alloc& a_alloc = Alloc())
     throw (err_bad_argument)
 {
     detail::check_node_length(node.size());
     init(node, id, creation, a_alloc);
 }
Example #20
0
receptor::receptor(istream& is, const box& b) : partitions(b.num_partitions)
{
	// Initialize necessary variables for constructing a receptor.
	atoms.reserve(5000); // A receptor typically consists of <= 5,000 atoms.

	// Initialize helper variables for parsing.
	string residue = "XXXX"; // Current residue sequence, used to track residue change, initialized to a dummy value.
	vector<size_t> residues;
	residues.reserve(1000); // A receptor typically consists of <= 1,000 residues, including metal ions and water molecules if any.
	size_t num_lines = 0; // Used to track line number for reporting parsing errors, if any.
	string line;
	line.reserve(79); // According to PDBQT specification, the last item AutoDock atom type locates at 1-based [78, 79].

	// Parse ATOM/HETATM.
	while (getline(is, line))
	{
		++num_lines;
		if (starts_with(line, "ATOM") || starts_with(line, "HETATM"))
		{
			// Parse and validate AutoDock4 atom type.
			const string ad_type_string = line.substr(77, isspace(line[78]) ? 1 : 2);
			const size_t ad = parse_ad_type_string(ad_type_string);
			if (ad == AD_TYPE_SIZE) continue;

			// Skip non-polar hydrogens.
			if (ad == AD_TYPE_H) continue;

			// Parse the Cartesian coordinate.
			string name = line.substr(12, 4);
			boost::algorithm::trim(name);
			const atom a(line.substr(21, 1) + ':' + line.substr(17, 3) + right_cast<string>(line, 23, 26) + ':' + name, vec3(right_cast<fl>(line, 31, 38), right_cast<fl>(line, 39, 46), right_cast<fl>(line, 47, 54)), ad);

			// For a polar hydrogen, the bonded hetero atom must be a hydrogen bond donor.
			if (ad == AD_TYPE_HD)
			{
				const size_t residue_start = residues.back();
				for (size_t i = atoms.size(); i > residue_start;)
				{
					atom& b = atoms[--i];
					if (!b.is_hetero()) continue; // Only a hetero atom can be a hydrogen bond donor.
					if (a.is_neighbor(b))
					{
						b.donorize();
						break;
					}
				}
			}
			else // It is a heavy atom.
			{
				// Parse the residue sequence located at 1-based [23, 26].
				if ((line[25] != residue[3]) || (line[24] != residue[2]) || (line[23] != residue[1]) || (line[22] != residue[0])) // This line is the start of a new residue.
				{
					residue[3] = line[25];
					residue[2] = line[24];
					residue[1] = line[23];
					residue[0] = line[22];
					residues.push_back(atoms.size());
				}
				atoms.push_back(a);
			}
		}
		else if (starts_with(line, "TER"))
		{
			residue = "XXXX";
		}
	}

	// Dehydrophobicize carbons if necessary.
	const size_t num_residues = residues.size();
	residues.push_back(atoms.size());
	for (size_t r = 0; r < num_residues; ++r)
	{
		const size_t begin = residues[r];
		const size_t end = residues[r + 1];
		for (size_t i = begin; i < end; ++i)
		{
			const atom& a = atoms[i];
			if (!a.is_hetero()) continue; // a is a hetero atom.

			for (size_t j = begin; j < end; ++j)
			{
				atom& b = atoms[j];
				if (b.is_hetero()) continue; // b is a carbon atom.

				// If carbon atom b is bonded to hetero atom a, b is no longer a hydrophobic atom.
				if (a.is_neighbor(b))
				{
					b.dehydrophobicize();
				}
			}
		}
	}
	
	// Find all the heavy receptor atoms that are within 8A of the box.
	vector<size_t> receptor_atoms_within_cutoff;
	receptor_atoms_within_cutoff.reserve(atoms.size());
	const size_t num_rec_atoms = atoms.size();
	for (size_t i = 0; i < num_rec_atoms; ++i)
	{
		const atom& a = atoms[i];
		if (b.project_distance_sqr(a.coordinate) < scoring_function::Cutoff_Sqr)
		{
			receptor_atoms_within_cutoff.push_back(i);
		}
	}
	const size_t num_receptor_atoms_within_cutoff = receptor_atoms_within_cutoff.size();

	// Allocate each nearby receptor atom to its corresponding partition.
	for (size_t x = 0; x < b.num_partitions[0]; ++x)
	for (size_t y = 0; y < b.num_partitions[1]; ++y)
	for (size_t z = 0; z < b.num_partitions[2]; ++z)
	{
		vector<size_t>& par = partitions(x, y, z);
		par.reserve(num_receptor_atoms_within_cutoff);
		const array<size_t, 3> index1 = {{ x,     y,     z     }};
		const array<size_t, 3> index2 = {{ x + 1, y + 1, z + 1 }};
		const vec3 corner1 = b.partition_corner1(index1);
		const vec3 corner2 = b.partition_corner1(index2);
		for (size_t l = 0; l < num_receptor_atoms_within_cutoff; ++l)
		{
			const size_t i = receptor_atoms_within_cutoff[l];
			const atom& a = atoms[i];
			const fl proj_dist_sqr = b.project_distance_sqr(corner1, corner2, a.coordinate);
			if (proj_dist_sqr < scoring_function::Cutoff_Sqr)
			{
				par.push_back(i);
			}
		}
	}
}