예제 #1
0
def main():
    args = parse_args()
    try:
        os.makedirs(args.directory)
    except OSError:
        pass

    structure = Structure.fromfile(args.structure).reorder()


    for residue in structure.extract('record',"ATOM").extract(
      'resn', "HOH","!=").residue_groups:
        altlocs = sorted(list(set(residue.altloc)))
        resi = residue.resi[0]
        chainid = residue.chain[0]
        tot_rmsd = 0.0
        numlocs = 0
        if len(altlocs) > 1:
            try:
                altlocs.remove('')
            except ValueError:
                pass
            for altloc in altlocs:
                conf1 = residue.extract('altloc',altloc)
                for altloc2 in altlocs:
                    if altloc != altloc2:
                        conf2 = residue.extract('altloc',altloc2)
                        rmsd = conf1.rmsd(conf2)
                        tot_rmsd += rmsd
                        numlocs += 1
                if numlocs > 0:
                        print(resi,chainid,round(tot_rmsd/numlocs,2),len(altlocs))
        else:
            print(resi,chainid,0.0,len(altlocs))
예제 #2
0
def main():
    args = parse_args()
    try:
        structure = Structure.fromfile(args.structure)
    except Exception as e:
        raise type(
            e)('qFit requires a valid structure file, but could not find one'
               ) from e
    ligands = structure.extract('record', 'HETATM')
    max_lig = 0
    lig_name = None
    for chain in np.unique(ligands.chain):
        ligand2 = ligands.extract('chain', chain, '==')
        for ligand_name in list(set(ligand2.resn)):
            if ligand_name not in known_ligands:
                ligand = ligand2.extract('resn', ligand_name, '==')
                mask = ligand.e != 'H'
                if len(mask) >= 10:
                    if len(ligand.name[mask]) > max_lig:
                        max_lig = len(ligand.name[mask])
                        lig_name = ligand_name

    if lig_name:
        with open('args.pdb' + '_ligand_name.txt', 'w') as file:
            file.write(lig_name)
예제 #3
0
def main():
    args = parse_args()
    structure = Structure.fromfile(args.structure)
    structure_resi = structure.extract('resn', args.lig_name)
    chain = np.unique(structure_resi.chain)
    resi = np.unique(structure_resi.resi)
    chain2 = ' '.join(map(str, chain))
    resi2 = ' '.join(map(str, resi))

    with open(args.lig_name + '_chain_resi.txt', 'w') as file:
           file.write(chain2 + ',' + resi2)
예제 #4
0
def main():
    args = parse_args()
    print(args)
    try:
        os.mkdir(args.directory)
    except OSError:
        pass
    # Load structure and prepare it
    apo_structure = Structure.fromfile(
        args.apo_structure).reorder()  #put H20 on the bottom
    print(apo_structure)
    apo_structure = apo_structure.extract('e', 'H', '!=')
    holo_structure = Structure.fromfile(
        args.holo_structure).reorder()  #put H20 on the bottom
    holo_structure = holo_structure.extract('e', 'H', '!=')
    options_multi = QFitMultiResOptions()
    options_multi.apply_command_args(args)
    time0 = time.time()
    sub_structure = QFitMultiResidue(holo_structure, apo_structure,
                                     options_multi)
    substructure = sub_structure.run()
    print(f"Total time: {time.time() - time0}s")
예제 #5
0
def _main():
    # Collect and act on arguments
    #   (When args==None, argparse will default to sys.argv[1:])
    argparser = _build_argparser()
    cmdline_args = argparser.parse_args(args=None)

    try:
        os.mkdir(cmdline_args.directory)
    except OSError:
        pass

    # Run main script
    get_metrics(Structure.fromfile(cmdline_args.structure).reorder())
예제 #6
0
def get_metrics(structure: Structure) -> None:
    """Calculate RMSF by residue and altloc.

    Iterate through altlocs of each residue,
    reporting mean heavy-atom RMSD from all other altlocs of the residue."""

    # Print a column header
    print("resi", "chain", "residue_altloc_rmsd", "n_altlocs")

    for residue in (
            structure.extract('record', "ATOM")  # Don't analyse metals/ligands
            .extract('resn', "HOH", "!=")  # Don't analyse waters
            .extract(
                'name', "H", "!="
            )  # Sometimes backbone N-H atoms are present in some altlocs, not all. Avoid analysing them.
            .extract(
                'e', "H", "!="
            )  # Sometimes His protonation states differ between altlocs. Avoid analysing all H.
    ).residue_groups:
        altlocs = sorted(list(set(residue.altloc)))
        resi = residue.resi[0]
        chainid = residue.chain[0]

        # Guard: if there's only 1 altloc at this residue...
        if len(altlocs) == 1:
            print(resi, chainid, 0., len(altlocs))
            continue

        try:
            altlocs.remove(
                '')  # Remove the 'common backbone' from analysis, if present
        except ValueError:
            pass

        for altloc1, remaining_altlocs in pivot_and_remainder(altlocs):
            conf1 = residue.extract('altloc', altloc1)
            tot_rmsd: float = 0.
            numlocs: int = 0

            for altloc2 in remaining_altlocs:
                conf2 = residue.extract('altloc', altloc2)
                tot_rmsd += conf1.rmsd(conf2)
                numlocs += 1

            try:
                avg_rmsd: float = tot_rmsd / numlocs
            except ZeroDivisionError:
                avg_rmsd = 0.

            print(resi, chainid, round(avg_rmsd, 2), len(altlocs))
예제 #7
0
p.add_argument("-d", "--directory", help="Directory where results are stored.")
p.add_argument("-p",
               "--nprocessors",
               type=int,
               default=1,
               help="Number of processors to run.")
p.add_argument(
    '-bb',
    '--backbone',
    action='store_true',
    help="Sample backbone locally using inverse kinematics null space sampling."
)

args = p.parse_args()

s = Structure.fromfile(args.structure)
run_dirs = []
selections = []
for chain in s.chains:
    chainid = chain.chain[0]
    conformer = chain.conformers[0]
    for residue in conformer.residues:
        resseq, icode = residue.id
        sel = f'{chainid},{resseq}'
        if icode:
            sel += f':{icode}'
        run_dir = os.path.join(args.directory, f'{chainid}_{resseq}{icode}')

        run_dirs.append(run_dir)
        selections.append(sel)