Esempio n. 1
0
                        break

                if clashing:
                    break

            if clashing:
                skipped += 1
                continue

        if args.outfile is None:
            s += print_geom.write(outfile=False)
            s += "\n"
        else:
            if os.path.isdir(os.path.expanduser(args.outfile)):
                outfile = os.path.join(os.path.expanduser(args.outfile),
                                       "conformer-%i.xyz" % (conf + 1))

            else:
                outfile = args.outfile.replace("$i", str(conf + 1))

            if "$INFILE" in outfile:
                outfile = outfile.replace("$INFILE", get_filename(infile))

            print_geom.write(outfile=outfile, append="$i" not in args.outfile)

if args.outfile is None or args.list_info:
    print(s[:-1])

if skipped > 0:
    print("%i conformers skipped because of clashing substituent(s)" % skipped)
Esempio n. 2
0
        geom.change_distance(a1, a2, dist=vals[2], adjust=True)

    #print specified bonds
    out = ""
    for bond in args.measure:
        a1 = geom.find(str(bond[0]))[0]
        a2 = geom.find(str(bond[1]))[0]
        val = a1.dist(a2)
        out += "%f\n" % val

    out = out.rstrip()

    if len(args.set_ang) + len(args.change) > 0:
        if args.outfile:
            outfile = args.outfile
            if "$INFILE" in outfile:
                outfile = outfile.replace("$INFILE", get_filename(f))
            geom.write(append=True, outfile=outfile)
        else:
            print(geom.write(outfile=False))

    if len(args.measure) > 0:
        if not args.outfile:
            print(out)
        else:
            outfile = args.outfile
            if "$INFILE" in outfile:
                outfile = outfile.replace("$INFILE", get_filename(f))
            with open(outfile, "a") as f:
                f.write(out)
Esempio n. 3
0
                outfile = outfiles[i].replace("$i", fmt % k)
            else:
                outfile = outfiles[i]

            followed_geom = pathway.geom_func(t)
            followed_geom.comment = (
                "animating mode %s scaled to displace at most [%s]" % (
                    repr(mode),
                    ", ".join(
                        str(pathway.var_func[key](t)) for key in other_vars),
                ))
            if args.outfile:
                followed_geom.write(append=False,
                                    outfile=outfile.replace(
                                        "$INFILE",
                                        get_filename(args.input_file)))
            else:
                print(followed_geom.write(outfile=False))

    else:
        w = width(len(modes))
        fmt = "%0" + "%i" % w + "i"

        followed_geom = geom.copy()
        followed_geom.update_geometry(geom.coords + dX)
        followed_geom.comment = "following mode %s scaled to displace at most %s" % (
            repr(mode),
            repr(scale[i]),
        )

        outfile = outfiles[i]
Esempio n. 4
0
            original_ligands = [l for l in ligands]

            lig_keys = sum([len(ligand.key_atoms) for ligand in ligands])
            while len(key) > lig_keys:
                ligands.extend(l.copy() for l in original_ligands)
                lig_keys += sum(
                    [len(ligand.key_atoms) for ligand in original_ligands])

            j = 0
            while len(key) < sum([len(ligand.key_atoms)
                                  for ligand in ligands]):
                if j >= len(cat.components["ligand"]):
                    raise RuntimeError(
                        "new ligand appears to have a higher denticity than old ligands combined"
                    )

                key.extend(cat.components["ligand"][j].key_atoms)
                j += 1

            cat_copy.map_ligand(ligands, key)

            if args.outfile:
                if "$INFILE" in args.outfile:
                    outfile = args.outfile.replace("$INFILE",
                                                   get_filename(infile))
                outfile = outfile.replace("$LIGAND", lig_name)
                cat_copy.write(append=False, outfile=outfile)
            else:
                s = cat_copy.write(outfile=False)
                print(s)
Esempio n. 5
0
def ligandSterimol(session,
                   selection,
                   radii="UMN",
                   showVectors=True,
                   showRadii=True,
                   at_L=None,
                   bisect_L=False,
                   return_values=False):
    models, center, key_atoms = avoidTargets(session.logger, selection)

    radii = radii.lower()

    targets = []
    coord_atoms = []
    datas = []

    info = "<pre>model\tcoord. atoms\tB1\tB2\tB3\tB4\tB5\tL\n"

    # if return_values:
    # if len(models.keys()) > 1:
    #     raise RuntimeError("only one substituent may be selected")

    # if any(len(models[key]) > 1 for key in models.keys()):
    #     raise RuntimeError("only one substituent may be selected")

    for model in models:
        rescol = ResidueCollection(model)
        comp_atoms = [AtomSpec(at.atomspec) for at in models[model]]
        key_atomspec = [AtomSpec(at.atomspec) for at in key_atoms[model]]
        center_atomspec = [AtomSpec(at.atomspec) for at in center[model]]
        if len(center_atomspec) != 1:
            session.logger.error(
                "ligand sterimol requires one central atom to which " + \
                "the ligand is coordinated\n" + \
                "%i were found on model %s:\n" % (len(center_atomspec), model.atomspec) + \
                "\n".join([at.atomspec for at in center[model]])
            )
            continue

        comp = Component(
            rescol.find(comp_atoms),
            to_center=rescol.find(center_atomspec),
            key_atoms=rescol.find(key_atomspec),
        )

        data = comp.sterimol(
            return_vector=True,
            radii=radii,
            at_L=at_L,
            to_center=rescol.find(center_atomspec),
            bisect_L=bisect_L,
        )
        l = np.linalg.norm(data["L"][1] - data["L"][0])
        b1 = np.linalg.norm(data["B1"][1] - data["B1"][0])
        b2 = np.linalg.norm(data["B2"][1] - data["B2"][0])
        b3 = np.linalg.norm(data["B3"][1] - data["B3"][0])
        b4 = np.linalg.norm(data["B4"][1] - data["B4"][0])
        b5 = np.linalg.norm(data["B5"][1] - data["B5"][0])

        if showVectors:
            for key, color in zip(
                ["B1", "B2", "B3", "B4", "B5", "L"],
                ["black", "green", "purple", "orange", "red", "blue"]):
                start, end = data[key]
                s = ".color %s\n" % color
                s += ".note Sterimol %s\n" % key
                s += ".arrow %6.3f %6.3f %6.3f   %6.3f %6.3f %6.3f\n" % (
                    *start, *end)

                stream = BytesIO(bytes(s, "utf-8"))
                bild_obj, status = read_bild(session, stream,
                                             "Sterimol %s" % key)

                session.models.add(bild_obj, parent=model)

        if showRadii:
            s = ".note radii\n"
            s += ".transparency 75\n"
            color = None
            for atom in comp.atoms:
                chix_atom = atom.chix_atom
                if radii == "umn":
                    r = VDW_RADII[chix_atom.element.name]
                elif radii == "bondi":
                    r = BONDI_RADII[chix_atom.element.name]

                if color is None or chix_atom.color != color:
                    color = chix_atom.color
                    rgb = [x / 255. for x in chix_atom.color]
                    rgb.pop(-1)

                    s += ".color %f %f %f\n" % tuple(rgb)

                s += ".sphere %f %f %f %f\n" % (*chix_atom.coord, r)

            stream = BytesIO(bytes(s, "utf-8"))
            bild_obj, status = read_bild(session, stream, "Sterimol radii")

            session.models.add(bild_obj, parent=model)

        name = get_filename(model.name, include_parent_dir=False)

        info += "%-16s\t%-11s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n" % (
            name, ", ".join(at.atomspec
                            for at in key_atoms[model]), b1, b2, b3, b4, b5, l)
        targets.append(name)
        coord_atoms.append([at.atomspec for at in key_atoms[model]])
        datas.append(data)

    info = info.strip()
    info += "</pre>"
    if not return_values:
        session.logger.info(info, is_html=True)

    if return_values:
        return targets, coord_atoms, datas
Esempio n. 6
0
def sterimol(
        session,
        selection,
        radii="UMN",
        showVectors=True,
        showRadii=True,
        LCorrection="FORTRAN",
        return_values=False
    ):
    models, attached = avoidTargets(session.logger, selection)
    
    radii = radii.lower()

    old_L = False
    if LCorrection.upper() == "FORTRAN":
        old_L = True

    model_names = []
    targets = []
    datas = []
    
    info = "<pre>model\tsubstituent atom\tB1\tB2\tB3\tB4\tB5\tL\n"
    
    # if return_values:
        # if len(models.keys()) > 1:
        #     raise RuntimeError("only one substituent may be selected")
        
        # if any(len(models[key]) > 1 for key in models.keys()):
        #     raise RuntimeError("only one substituent may be selected")
    
    for model in models:
        rescol = ResidueCollection(model, refresh_ranks=False)
        for res in models[model]:
            for target in models[model][res]:
                end_atomspec = AtomSpec(attached[target].atomspec)
                start_atomspec = AtomSpec(target.atomspec)
                
                sub_atoms = rescol.get_fragment(start_atomspec, end_atomspec)
                sub = Substituent(
                    sub_atoms, 
                    end=rescol.find_exact(end_atomspec)[0], 
                    detect=False,
                )
                
                data = sub.sterimol(
                    return_vector=True,
                    radii=radii,
                    old_L=old_L,
                )
                l = np.linalg.norm(data["L"][1] - data["L"][0])
                b1 = np.linalg.norm(data["B1"][1] - data["B1"][0])
                b2 = np.linalg.norm(data["B2"][1] - data["B2"][0])
                b3 = np.linalg.norm(data["B3"][1] - data["B3"][0])
                b4 = np.linalg.norm(data["B4"][1] - data["B4"][0])
                b5 = np.linalg.norm(data["B5"][1] - data["B5"][0])
                
                if showVectors:
                    for key, color in zip(
                            ["B1", "B2", "B3", "B4", "B5", "L"],
                            ["black", "green", "purple", "orange", "red", "blue"]
                    ):
                        start, end = data[key]
                        s = ".color %s\n" % color
                        s += ".note Sterimol %s\n" % key
                        s += ".arrow %6.3f %6.3f %6.3f   %6.3f %6.3f %6.3f\n" % (*start, *end)
                        
                        stream = BytesIO(bytes(s, "utf-8"))
                        bild_obj, status = read_bild(session, stream, "Sterimol %s" % key)
                        
                        session.models.add(bild_obj, parent=model)
                    
                if showRadii:
                    s = ".note radii\n"
                    s += ".transparency 75\n"
                    color = None
                    for atom in sub.atoms:
                        chix_atom = atom.chix_atom
                        if radii == "umn":
                            r = VDW_RADII[chix_atom.element.name]
                        elif radii == "bondi":
                            r = BONDI_RADII[chix_atom.element.name]
                        
                        if color is None or chix_atom.color != color:
                            color = chix_atom.color
                            rgb = [x/255. for x in chix_atom.color]
                            rgb.pop(-1)
                            
                            s += ".color %f %f %f\n" % tuple(rgb)
                        
                        s += ".sphere %f %f %f %f\n" % (*chix_atom.coord, r)
                
                    stream = BytesIO(bytes(s, "utf-8"))
                    bild_obj, status = read_bild(session, stream, "Sterimol radii")
                    
                    session.models.add(bild_obj, parent=model)
                
                model_name = get_filename(model.name, include_parent_dir=False)
                
                info += "%-16s\t%-11s\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n" % (
                    model_name,
                    target.atomspec,
                    b1, b2, b3, b4, b5, l
                )
                model_names.append(model_name)
                targets.append(target.atomspec)
                datas.append(data)
    
    info = info.strip()
    info += "</pre>"
    if not return_values:
        session.logger.info(info, is_html=True)
    
    if return_values:
        return model_names, targets, datas
Esempio n. 7
0
    fig = plt.gcf()
    fig.clear()

    freq.plot_ir(
        fig,
        centers=args.centers,
        widths=args.widths,
        plot_type=args.plot_type,
        peak_type=args.peak_type,
        reverse_x=args.reverse_x,
        fwhm=args.fwhm,
        point_spacing=args.point_spacing,
        voigt_mixing=args.voigt_mixing,
        linear_scale=args.linear_scale,
        quadratic_scale=args.quadratic_scale,
        exp_data=exp_data,
        anharmonic=freq.anharm_data and args.anharmonic,
    )

    if args.fig_width:
        fig.set_figwidth(args.fig_width)

    if args.fig_height:
        fig.set_figheight(args.fig_height)

    if args.outfile:
        outfile_name = args.outfile.replace("$INFILE", get_filename(f))
        plt.savefig(outfile_name, dpi=300)
    else:
        plt.show()
Esempio n. 8
0
s = ""
unique = 0
total = 0
for n_atoms in structures:
    for formula in structures[n_atoms]:
        formula_unique = len(structures[n_atoms][formula])
        unique += formula_unique
        s += "%s\n" % formula

        for group in structures[n_atoms][formula]:
            total += len(group)
            if args.directory:
                dir_name = os.path.join(
                    args.directory,
                    formula,
                    get_filename(group[0][0].name, include_parent_dir=False),
                )
                if not os.path.exists(dir_name):
                    os.makedirs(dir_name)
                for geom, rmsd, _ in group:
                    geom.comment = "RMSD from %s = %.4f" % (
                        get_filename(group[0][0].name,
                                     include_parent_dir=False),
                        rmsd,
                    )
                    if args.energy_filter and all(
                            "energy" in g.other for g in [geom, group[0][0]]):
                        d_nrg = UNIT.HART_TO_KCAL * (
                            geom.other["energy"] - group[0][0].other["energy"])
                        geom.comment += "  energy from %s = %.1f kcal/mol" % (
                            get_filename(group[0][0].name,