Beispiel #1
0
	static void writeKeyValueMap( 
							PolymorphicSharedPtr<KeyspaceStorage>& inStorage,
							boost::python::dict& keysAndValues
							)
		{
		map<SharedState::Key, KeyState> state;

		boost::python::list keys = keysAndValues.keys();

		long len = boost::python::len(keys);

		for (long k = 0; k < len; k++)
			{
			state[boost::python::extract<SharedState::Key>(keys[k])()] = 
				KeyState(
					null() << ValueType(
						null() << PythonWrapper<SharedState::View>::pyToJsonOrError(keysAndValues[keys[k]]),
						UniqueId()
						),
					null() << UniqueId(),
					std::map<UniqueId, PartialEvent>()
					);
			}

		inStorage->writeStateExternal(state);
		}
Beispiel #2
0
INT_VECT EmbedMultipleConfs(
    ROMol &mol, unsigned int numConfs, unsigned int maxAttempts, int seed,
    bool clearConfs, bool useRandomCoords, double boxSizeMult, bool randNegEig,
    unsigned int numZeroFail, double pruneRmsThresh, python::dict &coordMap,
    double forceTol, bool ignoreSmoothingFailures, bool enforceChirality,
    int numThreads, bool useExpTorsionAnglePrefs, bool useBasicKnowledge,
    bool printExpTorsionAngles) {
  std::map<int, RDGeom::Point3D> pMap;
  python::list ks = coordMap.keys();
  unsigned int nKeys = python::extract<unsigned int>(ks.attr("__len__")());
  for (unsigned int i = 0; i < nKeys; ++i) {
    unsigned int id = python::extract<unsigned int>(ks[i]);
    pMap[id] = python::extract<RDGeom::Point3D>(coordMap[id]);
  }
  std::map<int, RDGeom::Point3D> *pMapPtr = 0;
  if (nKeys) {
    pMapPtr = &pMap;
  }

  INT_VECT res;
  {
    NOGIL gil;
    DGeomHelpers::EmbedMultipleConfs(
        mol, res, numConfs, numThreads, maxAttempts, seed, clearConfs,
        useRandomCoords, boxSizeMult, randNegEig, numZeroFail, pruneRmsThresh,
        pMapPtr, forceTol, ignoreSmoothingFailures, enforceChirality,
        useExpTorsionAnglePrefs, useBasicKnowledge, printExpTorsionAngles);
  }
  return res;
}
Beispiel #3
0
unsigned int Compute2DCoords(RDKit::ROMol &mol, bool canonOrient,
                             bool clearConfs, python::dict &coordMap,
                             unsigned int nFlipsPerSample = 3,
                             unsigned int nSamples = 100, int sampleSeed = 100,
                             bool permuteDeg4Nodes = false,
                             double bondLength = -1.0) {
  RDGeom::INT_POINT2D_MAP cMap;
  cMap.clear();
  python::list ks = coordMap.keys();
  for (unsigned int i = 0;
       i < python::extract<unsigned int>(ks.attr("__len__")()); i++) {
    unsigned int id = python::extract<unsigned int>(ks[i]);
    if (id >= mol.getNumAtoms()) {
      throw_value_error("atom index out of range");
    }
    cMap[id] = python::extract<RDGeom::Point2D>(coordMap[id]);
  }
  double oBondLen = RDDepict::BOND_LEN;
  if (bondLength > 0) {
    RDDepict::BOND_LEN = bondLength;
  }
  unsigned int res;
  res = RDDepict::compute2DCoords(mol, &cMap, canonOrient, clearConfs,
                                  nFlipsPerSample, nSamples, sampleSeed,
                                  permuteDeg4Nodes);
  if (bondLength > 0) {
    RDDepict::BOND_LEN = oBondLen;
  }
  return res;
}
Beispiel #4
0
void clientW::connect(const std::string& uri, const boost::python::dict& query){
	std::map<std::string, std::string> newmap;
	int len = boost::python::len(query);
	boost::python::list keys = query.keys();
	for(int i=0; i < len; i++) {
		std::string k = boost::python::extract<std::string>(keys[i]);
		newmap[k] = boost::python::extract<std::string>(query[k]);
	}
	this->client::connect(uri,newmap);
}
Beispiel #5
0
 map<string,double> extract_solution(boost::python::dict pySol)
 {
   boost::python::list sol_keys = pySol.keys();
   map<string,double> sol;
   for(int iter = 0; iter < len(sol_keys); ++iter)
   {
     boost::python::extract<std::string> key(sol_keys[iter]);
     boost::python::extract<double> value(pySol[sol_keys[iter]]);
     sol[key] = value;
   }
   return sol;
 }
Beispiel #6
0
    static mapnik::attributes dict2attr(boost::python::dict const& d)
    {
        using namespace boost::python;
        mapnik::attributes vars;
        mapnik::transcoder tr_("utf8");
        boost::python::list keys=d.keys();
        for (int i=0; i < len(keys); ++i)
        {
            std::string key = extract<std::string>(keys[i]);
            object obj = d[key];
            if (PyUnicode_Check(obj.ptr()))
            {
                PyObject* temp = PyUnicode_AsUTF8String(obj.ptr());
                if (temp)
                {
    #if PY_VERSION_HEX >= 0x03000000
                    char* c_str = PyBytes_AsString(temp);
    #else
                    char* c_str = PyString_AsString(temp);
    #endif
                    vars[key] = tr_.transcode(c_str);
                    Py_DecRef(temp);
                }
                continue;
            }

            extract<std::string> ex0(obj);
            if (ex0.check())
            {
                vars[key] = tr_.transcode(ex0().c_str());
                continue;
            }
            extract<mapnik::value_integer> ex2(obj);
            if (ex2.check())
            {
                vars[key] = ex2();
                continue;
            }
            extract<double> ex3(obj);
            if (ex3.check())
            {
                vars[key] = ex3();
                continue;
            }
            extract<mapnik::value_bool> ex1(obj);
            if (ex1.check())
            {
                vars[key] = ex1();
                continue;
            }
        }
        return vars;
    }
Beispiel #7
0
  map<string,Vec4d> extract_targets(boost::python::dict target_positions)
  {
    boost::python::list target_keys = target_positions.keys();
    map<string,Vec4d> target;
    for( int iter = 0; iter < len(target_keys); ++iter)
    {
      boost::python::extract<std::string> key(target_keys[iter]);
      boost::python::list value = boost::python::extract<boost::python::list>(target_positions[target_keys[iter]]);
      Vec4d v;
      assert(len(value) == 4);
      for(int jter = 0; jter < len(value); ++jter)
	v.values[jter] = boost::python::extract<double>(value[jter]);
      target[key] = v;
    }
    return target;
  }