Ejemplo n.º 1
0
    def from_file(cls,
                  db_file,
                  m="materials",
                  c="counter",
                  t="tasks",
                  **kwargs):
        """
        Get a TaskMaterialsBuilder using only a db file.

        Args:
            db_file (str): path to db file
            m (str): name of "materials" collection
            c (str): name of "counter" collection
            t (str): name of "tasks" collection
            **kwargs: other params to put into TasksMaterialsBuilder
        """
        db_write = get_database(db_file, admin=True)
        try:
            db_read = get_database(db_file, admin=False)
            db_read.collection_names()  # throw error if auth failed
        except:
            logger.warning(
                "Warning: could not get read-only database; using write creds")
            db_read = get_database(db_file, admin=True)
        return cls(db_write[m], db_write[c], db_read[t], **kwargs)
Ejemplo n.º 2
0
    def test_get_database(self):
        d = {"host": "localhost", "port": 27017, "database": "atomate_unittest"}

        self.assertTrue(isinstance(get_database(settings=d), Database))

        db = get_database(os.path.join(MODULE_DIR, "db.json"))
        self.assertTrue(isinstance(db, Database))
        self.assertEqual(db.client.address[0], "localhost")
        self.assertEqual(db.name, "atomate_unittest")
Ejemplo n.º 3
0
    def from_file(cls, db_file, m="materials", t="tasks", **kwargs):
        """
        Get a TagsCollector using only a db file.

        Args:
            db_file (str): path to db file
            m (str): name of "materials" collection
            **kwargs: other parameters to feed into the builder, e.g. update_all
        """
        db_write = get_database(db_file, admin=True)
        try:
            db_read = get_database(db_file, admin=False)
            db_read.collection_names()  # throw error if auth failed
        except:
            print("Warning: could not get read-only database; using write creds")
            db_read = get_database(db_file, admin=True)
        return cls(db_write[m], db_read[t], **kwargs)
Ejemplo n.º 4
0
 def from_file(cls, db_file, m="materials", **kwargs):
     """
     Get a MaterialsEhullBuilder using only a db file
     Args:
         db_file: (str) path to db file
         m: (str) name of "materials" collection
         **kwargs: other parameters to feed into the builder, e.g. mapi_key
     """
     db_write = get_database(db_file, admin=True)
     return cls(db_write[m], **kwargs)
Ejemplo n.º 5
0
    def from_file(cls, db_file, m="materials", b="boltztrap", **kwargs):
        """
        Get a BoltztrapMaterialsBuilder using only a db file.

        Args:
            db_file (str): path to db file
            m (str): name of "materials" collection
            b (str): name of "boltztrap" collection
            **kwargs: other params to put into BoltztrapMaterialsBuilder
        """
        db_write = get_database(db_file, admin=True)
        try:
            db_read = get_database(db_file, admin=False)
            db_read.collection_names()  # throw error if auth failed
        except:
            print("Warning: could not get read-only database")
            db_read = get_database(db_file, admin=True)

        return cls(db_write[m], db_read[b], **kwargs)
Ejemplo n.º 6
0
    def from_file(cls, db_file, m="materials", c="counter", t="tasks", **kwargs):
        """
        Get a TaskMaterialsBuilder using only a db file.

        Args:
            db_file (str): path to db file
            m (str): name of "materials" collection
            c (str): name of "counter" collection
            t (str): name of "tasks" collection
            **kwargs: other params to put into TasksMaterialsBuilder
        """
        db_write = get_database(db_file, admin=True)
        try:
            db_read = get_database(db_file, admin=False)
            db_read.collection_names()  # throw error if auth failed
        except:
            logger.warn("Warning: could not get read-only database; using write creds")
            db_read = get_database(db_file, admin=True)
        return cls(db_write[m], db_write[c], db_read[t], **kwargs)
Ejemplo n.º 7
0
    def from_file(cls, db_file, m="materials", b="boltztrap", **kwargs):
        """
        Get a BoltztrapMaterialsBuilder using only a db file.

        Args:
            db_file (str): path to db file
            m (str): name of "materials" collection
            b (str): name of "boltztrap" collection
            **kwargs: other params to put into BoltztrapMaterialsBuilder
        """
        db_write = get_database(db_file, admin=True)
        try:
            db_read = get_database(db_file, admin=False)
            db_read.collection_names()  # throw error if auth failed
        except:
            print("Warning: could not get read-only database")
            db_read = get_database(db_file, admin=True)

        return cls(db_write[m], db_read[b], **kwargs)
Ejemplo n.º 8
0
 def from_file(cls, db_file, m="materials", **kwargs):
     """
     Get a MaterialsEhullBuilder using only a db file
     Args:
         db_file: (str) path to db file
         m: (str) name of "materials" collection
         **kwargs: other parameters to feed into the builder, e.g. mapi_key
     """
     db_write = get_database(db_file, admin=True)
     return cls(db_write[m], **kwargs)
Ejemplo n.º 9
0
    def from_file(cls, db_file, t="tasks", **kwargs):
        """
        Get a FixTasksBuilder using only a db file.

        Args:
            db_file (str): path to db file
            t (str): name of "tasks" collection
            **kwargs: other params to put into FixTasksBuilder
        """
        db_write = get_database(db_file, admin=True)
        return cls(db_write[t], **kwargs)
Ejemplo n.º 10
0
    def from_file(cls, db_file, t="tasks", **kwargs):
        """
        Get a FixTasksBuilder using only a db file.

        Args:
            db_file (str): path to db file
            t (str): name of "tasks" collection
            **kwargs: other params to put into FixTasksBuilder
        """
        db_write = get_database(db_file, admin=True)
        return cls(db_write[t], **kwargs)
Ejemplo n.º 11
0
    def from_file(db_file, m="materials", **kwargs):
        """
        Get builder using only a db file.

        Args:
            db_file: (str) path to db file
            m: (str) name of "materials" collection
            **kwargs: other parameters to feed into the builder, e.g. mapi_key

        Returns:
            BandgapEstimationBuilder
        """
        db_write = get_database(db_file, admin=True)
        return BandgapEstimationBuilder(db_write[m], **kwargs)
Ejemplo n.º 12
0
    def from_file(db_file, m="materials", **kwargs):
        """
        Get builder using only a db file.

        Args:
            db_file: (str) path to db file
            m: (str) name of "materials" collection
            **kwargs: other parameters to feed into the builder, e.g. mapi_key

        Returns:
            BandgapEstimationBuilder
        """
        db_write = get_database(db_file, admin=True)
        return BandgapEstimationBuilder(db_write[m], **kwargs)
Ejemplo n.º 13
0
    def from_file(cls, db_file, data_file=None, m="materials", **kwargs):
        """
        Get a FileMaterialsBuilder using only a db file.

        Args:
            db_file (str): path to db file
            data_file (str): path to data file
            m (str): name of "materials" collection
            **kwargs: other parameters to feed into the builder, e.g. mapi_key
        """
        db_write = get_database(db_file, admin=True)
        if data_file:
            return cls(db_write[m], data_file, **kwargs)
        else:
            raise ValueError("data_file must be provided")
Ejemplo n.º 14
0
    def from_file(cls, db_file, data_file=None, m="materials", **kwargs):
        """
        Get a FileMaterialsBuilder using only a db file.

        Args:
            db_file (str): path to db file
            data_file (str): path to data file
            m (str): name of "materials" collection
            **kwargs: other parameters to feed into the builder, e.g. mapi_key
        """
        db_write = get_database(db_file, admin=True)
        if data_file:
            return cls(db_write[m], data_file, **kwargs)
        else:
            raise ValueError("data_file must be provided")