def test_read_card_with_subtitle(subtitled_stream, card_stream): from pylada.espresso.card import read_cards from six import StringIO stream = StringIO(subtitled_stream.read() + "\n" + card_stream.read()) result = read_cards(stream) assert len(result) == 2 assert result[0].name == 'k_points' assert result[0].subtitle == 'tpiba' assert result[0].value == "2\n0 0 0 0.8\n0.5 0.5 0.5 0.2" assert result[1].name == 'atomic_species' assert result[1].subtitle is None assert result[1].value == 'Al 1 this.that'
def test_read_card_with_namelist(subtitled_stream, card_stream): from pylada.espresso.card import read_cards from six import StringIO stream = StringIO(subtitled_stream.read() + "\n&electrons\nbullshit = 1\n/\n" + "\n" + card_stream.read()) result = read_cards(stream) assert len(result) == 2 assert result[0].name == "k_points" assert result[0].subtitle == "tpiba" assert result[0].value == "2\n0 0 0 0.8\n0.5 0.5 0.5 0.2" assert result[1].name == "atomic_species" assert result[1].subtitle is None assert result[1].value == "Al 1 this.that"
def test_add_forces(espresso, tmpdir, diamond_structure): from numpy import allclose, array from pylada.espresso.card import read_cards diamond_structure[1].force = [1, 2, 3] espresso.add_specie('Si', 'Al.vbc.UPF') tmpdir.join('pseudos', 'Al.vbc.UPF').ensure(file=True) espresso.write(str(tmpdir.join('al2.scf')), structure=diamond_structure) cards = read_cards(str(tmpdir.join('al2.scf'))) assert 'atomic_forces' in set([u.name for u in cards]) atomic_forces = [u for u in cards if u.name == 'atomic_forces'][0] assert atomic_forces.subtitle is None actual = atomic_forces.value.rstrip().lstrip().split('\n') assert len(actual) == 2 assert actual[0].split()[0] == 'Si' assert actual[1].split()[0] == 'Si' assert allclose(array(actual[0].split()[1:], dtype='float64'), 0) assert allclose(array(actual[1].split()[1:], dtype='float64'), [1, 2, 3])
def test_add_forces(espresso, tmpdir, diamond_structure): from numpy import allclose, array from pylada.espresso.card import read_cards diamond_structure[1].force = [1, 2, 3] espresso.add_specie("Si", "Al.vbc.UPF") tmpdir.join("pseudos", "Al.vbc.UPF").ensure(file=True) espresso.write(str(tmpdir.join("al2.scf")), structure=diamond_structure) cards = read_cards(str(tmpdir.join("al2.scf"))) assert "atomic_forces" in set([u.name for u in cards]) atomic_forces = [u for u in cards if u.name == "atomic_forces"][0] assert atomic_forces.subtitle is None actual = atomic_forces.value.rstrip().lstrip().split("\n") assert len(actual) == 2 assert actual[0].split()[0] == "Si" assert actual[1].split()[0] == "Si" assert allclose(array(actual[0].split()[1:], dtype="float64"), 0) assert allclose(array(actual[1].split()[1:], dtype="float64"), [1, 2, 3])