Esempio 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]
Esempio 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
Esempio 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
Esempio n. 4
0
def setup_lammps(opts):
    """Write LAMMPS simulation files."""
    # Read structure information
    coords = np.array(opts['cjson']['atoms']['coords']['3d'])
    atoms = [
        periodictable.elements[i].symbol
        for i in opts['cjson']['atoms']['elements']['number']
    ]
    nanocar = Molecule(atoms=atoms,
                       coordinates=np.array(coords).reshape(
                           (int(len(coords) / 3)), 3))
    opts['box_x'], opts['box_y'], opts[
        'box_z'] = opts['box_x'] * 10, opts['box_y'] * 10, opts['box_z'] * 10
    nanocar.set_cell([opts['box_x'], opts['box_y'], opts['box_z'], 90, 90, 90])
    nanocar.center([opts['box_x'] / 2, opts['box_y'] / 2, opts['box_z'] / 2])
    if not os.path.isdir(opts['dir']):
        # try removing the last part of the path (a file)
        parent = (Path(opts['dir']).parent.absolute())
        if not os.path.isdir(parent):
            opts['dir'] = PLUGIN_DIR
            print('Directory not found! Using plug-in directory -> %s' %
                  PLUGIN_DIR)
        else:
            opts['dir'] = parent
    data_file = os.path.join(opts['dir'], 'data.nanocar')
    write_data_file(data_file, nanocar)

    # Write input file
    surface_info = read_surface_info()
    surface_ids = surface_info['id']
    surface_atoms = surface_ids[1] - surface_ids[0]
    num_atoms = len(nanocar.atoms)
    if surface_ids[0] == 1:
        mol_ids = [num_atoms - surface_atoms, num_atoms]
    else:
        mol_ids = [1, num_atoms - surface_atoms - 1]
    input_file = os.path.join(opts['dir'], 'in.nanocar')
    inp_parameters = {
        'sim_length': opts['sim_length'],
        'ts': opts['timestep'],
        'mol_ids': mol_ids,
        'surface_ids': surface_ids,
        'T': 300
    }
    write_input_file(input_file, nanocar, inp_parameters)
Esempio n. 5
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