Exemplo n.º 1
0
def read_db(filename, index):
    import cmr
    r = cmr.read(filename)
    if "ase_positions" not in r and r.is_group():
        hashes = r.get_member_hashes()
        hashes = hashes[index]
        if len(hashes)==0:
            raise RuntimeError('cmr db-file: could not find any group members.\n'+
                               'This error could be caused by an older version of CMR - or a group file containing only references to other db-files.')
        if isinstance(hashes, list):
            return [get_atoms(r.get_xmldata(hash)) for hash in hashes]
        return get_atoms(r.get_xmldata(hashes))
    else:
        return get_atoms(r)
Exemplo n.º 2
0
import os
import warnings
# cmr calls all available methods in ase.atoms detected by the module inspect.
# Therefore also deprecated methods are called - and we choose to silence those warnings.
#warnings.filterwarnings('ignore', 'ase.atoms.*deprecated',)

import cmr

from ase.calculators.emt import EMT
from ase.structure import molecule

m1 = molecule('O2')
m1.set_calculator(EMT())
e1 = m1.get_potential_energy()

data = cmr.atoms2cmr(m1)
data.set_user_variable("molecule", "O2")
data.set_user_variable("potential", "EMT")
data.set_user_variable("db_keywords", ["O2", "EMT"])

data.write("O2.db")

reread = cmr.read("O2.db")
e2 = reread["ase_potential_energy"]
assert abs(e1-e2) < 1.e-6, str(e1) + ' ' + str(e2)

# clean
filename = "O2.db"
if os.path.exists(filename): os.unlink(filename)
Exemplo n.º 3
0
try:
    import cmr
except (Exception, ImportError):
    raise NotAvailable('CMR is required')

from ase.calculators.emt import EMT
from ase.io import read, write
from ase.structure import molecule

cmr_params = {"db_keywords":["O", "ase"], # keyword
              "molecule":"O2"} #field

m1 = molecule('O2')
m1.set_calculator(EMT())
e1 = m1.get_potential_energy()
write("O2.db", m1, cmr_params = cmr_params)

reread = read("O2.db")
e2 = reread.get_potential_energy()
assert abs(e1 - e2) < 1.e-6, str(e1) + ' ' + str(e2)

db_read = cmr.read("O2.db")
assert "O" in db_read["db_keywords"]
assert "ase" in db_read["db_keywords"]
assert db_read["molecule"] == "O2"

# clean
filename = "O2.db"
if os.path.exists(filename): os.unlink(filename)

calc = GPAW(mode=mode, xc=xc, h=h, txt=None)
system1.set_calculator(calc)
e = system1.get_potential_energy()
calc.write(formula)

# read gpw file
system2, calc2 = restart(formula, txt=None)
# write the information 'as in' gpw file into db file
# (called *db to avoid conflict with the *cmr file below)
if 1: # not used in this example
    calc2.write(formula + '.db', cmr_params=cmr_params)
# write the information 'as in' corresponding trajectory file into cmr file
write(cmrfile, system2, cmr_params=cmr_params)

# add the xc tag to the cmrfile
data = cmr.read(cmrfile)
data.set_user_variable('xc', xc)
data.write(cmrfile)

# perform PBE calculation on LDA density
ediff = calc2.get_xc_difference('PBE')

# add new results to the cmrfile
data = cmr.read(cmrfile)
data.set_user_variable('PBE', data['ase_potential_energy'] + ediff)
data.write(cmrfile)

# analyze the results with CMR
from cmr.ui import DirectoryReader

reader = DirectoryReader(directory='.', ext='.cmr')
Exemplo n.º 5
0
a = 4.05
d = a / 2 ** 0.5
bulk = Atoms([Atom('Al', (0, 0, 0)),
              Atom('Al', (0.5, 0.5, 0.5))],
             pbc=True)
bulk.set_cell((d, d, a), scale_atoms=True)
h = 0.18
calc = GPAW(h=h,
            nbands=2 * 8,
            kpts=(2, 2, 2),
            convergence={'energy': 1e-5})
bulk.set_calculator(calc)
e0 = bulk.get_potential_energy()

for ext in [".db", ".cmr"]:
    calc.write("test1"+ext)
    assert os.path.exists("test1"+ext)
    calc.write("test2"+ext, cmr_params={"value":1, "keywords":["a", "b"]})
    assert os.path.exists("test2"+ext)
    data = cmr.read("test2"+ext)
    assert data["value"] == 1
    assert len(data["db_keywords"]) == 2

# test the restart ability
if 0:
    calc = GPAW("test.db")
    calc.get_total_energy()
    calc = GPAW("test2.cmr")
    calc.get_total_energy()

Exemplo n.º 6
0
# Exception("CMR is not configured properly. Please create the settings file with cmr --create-settings.")
try:
    import cmr
except (Exception, ImportError):
    raise NotAvailable('CMR is required')

from ase.calculators.emt import EMT
from ase.io import read, write
from ase.structure import molecule

cmr_params = {"db_keywords":["O", "ase"], # keyword
              "molecule":"O2"} #field

m1 = molecule('O2')
m1.set_calculator(EMT())
e1 = m1.get_potential_energy()
write("O2.cmr", m1, cmr_params = cmr_params)

reread = read("O2.cmr")
e2 = reread.get_potential_energy()
assert abs(e1 - e2) < 1.e-6, str(e1) + ' ' + str(e2)

db_read = cmr.read("O2.cmr")
assert "O" in db_read["db_keywords"]
assert "ase" in db_read["db_keywords"]
assert db_read["molecule"] == "O2"

# clean
filename = "O2.cmr"
if os.path.exists(filename): os.unlink(filename)
Exemplo n.º 7
0
 def get_reader(name):
     reader = cmr.read(name,
                       read_mode=READ_DATA,
                       evaluation_mode=EVALUATE,
                       convertion_mode=CONVERTION_ORIGINAL)
     return reader
Exemplo n.º 8
0
 def get_reader(name):
     reader = cmr.read(name, mode=Flags.READ_MODE_ORIGINAL_TYPE)
     return reader
Exemplo n.º 9
0
from gpaw.mpi import world, rank

import warnings
# cmr calls all available methods in ase.atoms detected by the module inspect.
# Therefore also deprecated methods are called - and we choose to silence those warnings.
warnings.filterwarnings('ignore', 'ase.atoms.*deprecated',)

import cmr
# from cmr.tools.log import Log
# cmr.logger.set_message_selection(Log.MSG_TYPE_ALL)

a = 4.05
d = a / 2 ** 0.5
bulk = Atoms([Atom('Al', (0, 0, 0)),
              Atom('Al', (0.5, 0.5, 0.5))],
             pbc=True)
bulk.set_cell((d, d, a), scale_atoms=True)
h = 0.18
calc = GPAW(h=h,
            nbands=2 * 8,
            kpts=(2, 2, 2),
            convergence={'energy': 1e-5})
bulk.set_calculator(calc)
e0 = bulk.get_potential_energy()
calc.write("cmr_test3.gpw")

cmr.convert({"input":"cmr_test3.gpw", "output":"cmr_test3.cmr"})

data = cmr.read("cmr_test3.cmr")
data.dump()
Exemplo n.º 10
0
warnings.filterwarnings('ignore', 'ase.atoms.*deprecated',)

import cmr
# from cmr.tools.log import Log
# cmr.logger.set_message_selection(Log.MSG_TYPE_ALL)

a = 4.05
d = a / 2 ** 0.5
bulk = Atoms([Atom('Al', (0, 0, 0)),
              Atom('Al', (0.5, 0.5, 0.5))],
             pbc=True)
bulk.set_cell((d, d, a), scale_atoms=True)
h = 0.3

bulk.set_calculator(EMT())
e0 = bulk.get_potential_energy()
bulk.write("cmr_test4.traj")
bulk.write("cmr_test4a.cmr")

cmr.convert({"input":"cmr_test4.traj", "output":"cmr_test4.cmr"})

data = cmr.read("cmr_test4.cmr")
data.dump()

group = cmr.create_group()
group.add(data)
group.write("cmr_group4.cmr")

g = cmr.read("cmr_group4.cmr")
g.dump_all()