Exemplo n.º 1
0
def type_mof(filename, output_dir, ff="uff", output_files=True):

    obconversion = OBConversion()
    obconversion.SetInAndOutFormats("cif", "xyz")
    obmol = OBMol()

    # Read MOF file and unit cell and write xyz file
    obconversion.ReadFile(obmol, filename)
    unitcell = openbabel.toUnitCell(obmol.GetData(openbabel.UnitCell))
    uc = [
        unitcell.GetA(),
        unitcell.GetB(),
        unitcell.GetC(),
        unitcell.GetAlpha(),
        unitcell.GetBeta(),
        unitcell.GetGamma()
    ]
    obconversion.WriteFile(obmol, 'mof_tmp.xyz')

    # Replicate unit cell using angstrom
    mol = Molecule(read='mof_tmp.xyz')
    mol.set_cell(uc)
    n_atoms = len(mol.atoms)

    mol333 = mol.replicate([3, 3, 3], center=True)
    print(mol333.cell)
    mol333.write('mof333.cif', cell=mol333.cell.to_list())

    # Type FF
    obconversion.ReadFile(obmol, 'mof333.cif')
    ff = OBForceField.FindForceField("UFF")
    if not ff.Setup(obmol):
        print("Error: could not setup force field")
    ff.GetAtomTypes(obmol)

    # Get atom types for the middle cell
    types = []
    for atom_idx, obatom in enumerate(OBMolAtomIter(obmol)):
        if atom_idx >= n_atoms * 13 and atom_idx < n_atoms * 14:
            ff_atom_type = obatom.GetData("FFAtomType").GetValue()
            types.append(ff_atom_type)

    if output_files:
        mof_name = os.path.splitext(os.path.basename(filename))[0]
        with open(os.path.join(output_dir, mof_name + "-obabel.log"),
                  'w') as f:
            f.write("NOTE: types order is the same as the CIF input file.\n")
            f.write("types= %s" % str(types))

    uniq_types = sorted(set(types))
    return [str(i) for i in uniq_types]
Exemplo n.º 2
0
def test_piyzaz_replication_4_4_4_without_centering():
    """Tests replicating PIYZAZ (CCDC) 4x4x4 without centering.
    Reference structure is generated using Mercury software."""
    piyzaz = Molecule(read=piyzaz111_xyz)
    piyzaz.set_cell(piyzaz_cell_parameters)
    piyzaz444 = piyzaz.replicate([4, 4, 4], center=False)

    piyzaz444_ref = Molecule(read=piyzaz444_xyz)
    assert np.allclose(piyzaz444.coordinates, piyzaz444_ref.coordinates)
    assert set(piyzaz444.atoms) == set(piyzaz444_ref.atoms)
    assert piyzaz444.cell.a == piyzaz.cell.a * 4
    assert piyzaz444.cell.b == piyzaz.cell.b * 4
    assert piyzaz444.cell.c == piyzaz.cell.c * 4
    assert piyzaz444.cell.alpha == piyzaz.cell.alpha
    assert piyzaz444.cell.beta == piyzaz.cell.beta
    assert piyzaz444.cell.gamma == piyzaz.cell.gamma
Exemplo n.º 3
0
def test_piyzaz_replication_2_3_1_without_centering():
    """Tests replicating PIYZAZ (CCDC) 2x3x1 without centering.
    Reference structure is generated using Mercury software."""
    piyzaz = Molecule(read=piyzaz111_xyz)
    piyzaz.set_cell(piyzaz_cell_parameters)
    piyzaz231 = piyzaz.replicate([2, 3, 1], center=False)

    piyzaz231_ref = Molecule(read=piyzaz231_xyz)
    assert np.allclose(piyzaz231.coordinates, piyzaz231_ref.coordinates)
    assert set(piyzaz231.atoms) == set(piyzaz231_ref.atoms)
    assert piyzaz231.cell.a == piyzaz.cell.a * 2
    assert piyzaz231.cell.b == piyzaz.cell.b * 3
    assert piyzaz231.cell.c == piyzaz.cell.c * 1
    assert piyzaz231.cell.alpha == piyzaz.cell.alpha
    assert piyzaz231.cell.beta == piyzaz.cell.beta
    assert piyzaz231.cell.gamma == piyzaz.cell.gamma
Exemplo n.º 4
0
def test_piyzaz_replication_2_2_2_with_centering():
    """Tests replicating PIYZAZ (CCDC) 2x2x2 with centering.
    Reference structure is generated using Mercury software."""
    piyzaz = Molecule(read=piyzaz111_xyz)
    piyzaz.set_cell(piyzaz_cell_parameters)
    piyzaz222 = piyzaz.replicate([2, 2, 2], center=True)

    # Move the reference structure so that it's centered to original cell position
    piyzaz222_ref = Molecule(read=piyzaz222_xyz)
    transvec = np.sum(piyzaz.cell.vectors, axis=0) * -1 / 2
    piyzaz222_ref.translate(transvec)
    assert np.allclose(piyzaz222.coordinates, piyzaz222_ref.coordinates)
    assert set(piyzaz222.atoms) == set(piyzaz222_ref.atoms)
    assert piyzaz222.cell.a == piyzaz.cell.a * 2
    assert piyzaz222.cell.b == piyzaz.cell.b * 2
    assert piyzaz222.cell.c == piyzaz.cell.c * 2
    assert piyzaz222.cell.alpha == piyzaz.cell.alpha
    assert piyzaz222.cell.beta == piyzaz.cell.beta
    assert piyzaz222.cell.gamma == piyzaz.cell.gamma