Ejemplo n.º 1
0
def log_new_clusters(output_file, n, leader_list):

    print "log %d ligands. For change this number set the -n parameter" % n

    str_info = "\t%s\t  \t%20s\t %20s\t %20s\n" % ("File", "Model", "T.Energy",
                                                   "I.Energy")

    for i in range(0, n):
        str_info += "%s\t%20s\t%20s\t%20s\n" % (
            leader_list[i].getFileBelow().split('/').pop(),
            leader_list[i].getID(), leader_list[i].getTotalEnergy(),
            leader_list[i].getInteractionEnergy())

    out_log = file(output_file + ".log", "w")

    out_log.write(str_info)

    out_log.close()

    conv = OBConversion()

    conv.SetOutFormat("mol2")

    conv.WriteFile(leader_list[0], output_file + ".mol2")

    for i in range(1, n):
        conv.Write(leader_list[i])

    conv.CloseOutFile()
Ejemplo n.º 2
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]
Ejemplo n.º 3
0
def log_new_clusters(output_file, n, leader_list, ref=None):

    print "log %d ligands. For change this number set the -n parameter" % n

    str_info = "\t%s\t  %20s\t %20s\t %20s \t%15s\n" % (
        "File", "Model", "T.Energy", "I.Energy", "RMSD")

    if ref != None:
        mol_ref = loadReferenceMolecule(ref)

    if ref != None:
        for i in range(0, n):
            str_info += "%s\t%20s\t%20s\t%20s\t%15.3f\n" % (
                leader_list[i].getFileBelow(), leader_list[i].getID(),
                leader_list[i].getTotalEnergy(),
                leader_list[i].getInteractionEnergy(),
                getRMSD(leader_list[i], mol_ref))
    else:
        for i in range(0, n):
            str_info += "%s\t%20s\t%20s\t%20s\t%15.3f\n" % (
                leader_list[i].getFileBelow(), leader_list[i].getID(),
                leader_list[i].getTotalEnergy(),
                leader_list[i].getInteractionEnergy(),
                getRMSD(leader_list[i], leader_list[0]))

    out_log = file(output_file + ".log", "w")

    out_log.write(str_info)

    out_log.close()

    conv = OBConversion()

    conv.SetOutFormat("mol2")

    conv.WriteFile(leader_list[0], output_file + ".mol2")

    for i in range(1, n):
        conv.Write(leader_list[i])

    conv.CloseOutFile()