Example #1
0
    def test_run(self):
        db = DatabaseData(self.lp.name, collection="test_MongoEngineDBInsertionTask", username=self.lp.username,
                          password=self.lp.password)
        task = MongoEngineDBInsertionTask(db)
        fw = Firework([task], fw_id=1, spec={"_add_launchpad_and_fw_id": True})
        wf = Workflow([fw], metadata={'workflow_class': SaveDataWorkflow.workflow_class,
                                     'workflow_module': SaveDataWorkflow.workflow_module})
        self.lp.add_wf(wf)

        rapidfire(self.lp, self.fworker, m_dir=MODULE_DIR, nlaunches=1)

        wf = self.lp.get_wf_by_fw_id(1)

        assert wf.state == "COMPLETED"

        # retrived the saved object
        # error if not imported locally
        from abiflows.fireworks.tasks.tests.mock_objects import DataDocument
        db.connect_mongoengine()
        with db.switch_collection(DataDocument) as DataDocument:
            data = DataDocument.objects()

            assert len(data) == 1

            assert data[0].test_field_string == "test_text"
            assert data[0].test_field_int == 5
Example #2
0
    def test_run(self):
        db = DatabaseData(self.lp.name,
                          collection="test_MongoEngineDBInsertionTask",
                          username=self.lp.username,
                          password=self.lp.password)
        task = MongoEngineDBInsertionTask(db)
        fw = Firework([task], fw_id=1, spec={"_add_launchpad_and_fw_id": True})
        wf = Workflow(
            [fw],
            metadata={
                'workflow_class': SaveDataWorkflow.workflow_class,
                'workflow_module': SaveDataWorkflow.workflow_module
            })
        self.lp.add_wf(wf)

        rapidfire(self.lp, self.fworker, m_dir=MODULE_DIR, nlaunches=1)

        wf = self.lp.get_wf_by_fw_id(1)

        assert wf.state == "COMPLETED"

        # retrived the saved object
        # error if not imported locally
        from abiflows.fireworks.tasks.tests.mock_objects import DataDocument
        db.connect_mongoengine()
        with db.switch_collection(DataDocument) as DataDocument:
            data = DataDocument.objects()

            assert len(data) == 1

            assert data[0].test_field_string == "test_text"
            assert data[0].test_field_int == 5
Example #3
0
def db_data():
    """
    Creates an instance of DatabaseData with TESTDB_NAME and TESTCOLLECTION_NAME.
    Drops the collection.
    """
    db_data = DatabaseData(TESTDB_NAME, collection=TESTCOLLECTION_NAME)
    connection = db_data.connect_mongoengine()
    connection[TESTDB_NAME].drop_collection(TESTCOLLECTION_NAME)

    return db_data
Example #4
0
def db_data():
    """
    Creates an instance of DatabaseData with TESTDB_NAME and TESTCOLLECTION_NAME.
    Drops the collection.
    """
    db_data = DatabaseData(TESTDB_NAME, collection=TESTCOLLECTION_NAME)
    connection = db_data.connect_mongoengine()
    connection[TESTDB_NAME].drop_collection(TESTCOLLECTION_NAME)

    return db_data
Example #5
0
    def test_class(self):
        db = DatabaseData("test_db",
                          collection="test_collection",
                          username="******",
                          password="******")
        task = MongoEngineDBInsertionTask(db)

        self.assertFwSerializable(task)
Example #6
0
 def test_add_fws(self):
     assert len(self.scf_wf.wf.fws) == 1
     self.scf_wf.add_final_cleanup(out_exts=["WFK", "DEN"])
     assert len(self.scf_wf.wf.fws) == 2
     self.scf_wf.add_mongoengine_db_insertion(DatabaseData(TESTDB_NAME))
     assert len(self.scf_wf.wf.fws) == 3
     self.scf_wf.add_cut3d_den_to_cube_task()
     assert len(self.scf_wf.wf.fws) == 4
Example #7
0
 def from_dict(cls, m_dict):
     return cls(db_data=DatabaseData.from_dict(m_dict['db_data']))
Example #8
0
from abipy.abilab import Structure
from abiflows.fireworks.workflows.abinit_workflows import DfptFWWorkflow
from abiflows.database.mongoengine.utils import DatabaseData
from abiflows.database.mongoengine.abinit_results import RelaxResult

# data for the database where the relaxed structures were stored
source_db = DatabaseData(host='database_address', port=27017, collection='collection_name',
                         database='database_name', username='******', password='******')

# data for the database where the phonon results will be stored.
# note that these can be in different databases or in the same.
# The collections should be different
db = DatabaseData(host='database_address', port=27017, collection='another_collection_name',
                  database='database_name', username='******', password='******')

# Open the connection to the database
source_db.connect_mongoengine()

# in case you are using multiple workers for the same fireworks db (i.e. different clusters or queues)
# it may be a good idea to set the worker explicitly. One can just get the name from the configuration:
# fworker = FWorker.from_file(os.path.join(os.getenv("HOME"), ".fireworks", "my_fworker.yaml"))
# or you can also just write the name of the fworker explicitely
fworker_name = 'name_of_the_fworker'

mp_id = 'mp-149'

# This context manager is required to use the collection name selected in source_db
# By default mongoengine uses the name of the class (in this case RelaxResult) as
# name of the collection to query.
with source_db.switch_collection(RelaxResult) as RelaxResult:
    # download from the database the relaxed structure
Example #9
0
from abiflows.fireworks.workflows.abinit_workflows import RelaxFWWorkflow
from abiflows.database.mongoengine.utils import DatabaseData
from pymatgen import MPRester

# use the pseudo dojo table of pseudopotentials. These are good pseudopotentials. If you want to use
# some other kind of pseudos you will need to provide explicitly the cutoff for the calculation
pseudo_table = pseudo_dojo.OfficialDojoTable.from_djson_file(
    os.path.join(pseudo_dojo.dojotable_absdir("ONCVPSP-PBE-PDv0.4"),
                 'standard.djson'))
pseudo_path = pseudo_dojo.dojotable_absdir("ONCVPSP-PBE-PDv0.4")

# connection data of the output MongoDB database
# it can be the same database used for fireworks with other collections or a different one
db = DatabaseData(host='database_address',
                  port=27017,
                  collection='collection_name',
                  database='database_name',
                  username='******',
                  password='******')

# in case you are using multiple workers for the same fireworks db (i.e. different clusters or queues) it may be a good idea
# setting the worker explicitly. Here I just get the name
fworker = FWorker.from_file(
    os.path.join(os.getenv("HOME"), ".fireworks", "my_fworker.yaml"))

# Get the structure from the Materials Project. mp-149 is silicon.
mp_id = 'mp-149'
structure = MPRester().get_structure_by_material_id(mp_id)

# check if the pseudo is available and just selects those that are needed for the specific structure
try:
    pseudos = pseudo_table.get_pseudos_for_structure(structure)
Example #10
0
 def from_dict(cls, m_dict):
     return cls(db_data=DatabaseData.from_dict(m_dict['db_data']))