Esempio n. 1
0
def add_missing_heavy_atoms(molecular_system,
                            selection='all',
                            missing_heavy_atoms=None,
                            engine='PDBFixer',
                            syntaxis='MolSysMT'):

    engine = digest_engine(engine)

    output = None

    if engine == "PDBFixer":

        from molsysmt.basic import convert, get_form, select

        output_form = get_form(molecular_system)

        if missing_heavy_atoms is None:
            from molsysmt.build import get_missing_heavy_atoms
            missing_heavy_atoms = get_missing_heavy_atoms(molecular_system,
                                                          selection=selection,
                                                          syntaxis=syntaxis)

        tmp_molecular_system = convert(molecular_system,
                                       to_form="pdbfixer.PDBFixer")

        tmp_molecular_system.missingResidues = {}
        tmp_molecular_system.findMissingAtoms()
        tmp_molecular_system.missingTerminals = {}

        aux_dict = {}

        for group, atoms in tmp_molecular_system.missingAtoms.items():
            if group.index in missing_heavy_atoms:
                aux_dict[group] = []
                for atom in atoms:
                    if atom.name in missing_heavy_atoms[group.index]:
                        aux_dict[group].append(atom)

        tmp_molecular_system.missingAtoms = aux_dict

        tmp_molecular_system.addMissingAtoms()

        output = convert(tmp_molecular_system, to_form=output_form)

    else:

        raise NotImplementedError

    return output
Esempio n. 2
0
def potential_energy (molecular_system, selection='all', syntaxis='MolSysMT', engine='OpenMM'):

    from molsysmt._private.engines import digest_engine
    from molsysmt._private._digestion import digest_molecular_system
    from molsysmt.basic import convert

    engine=digest_engine(engine)

    if engine=='OpenMM':

        molecular_system = digest_molecular_system(molecular_system)
        if molecular_system.simulation_item is None:
            from molsysmt.native.simulation import simulation_to_potential_energy_minimization
            molecular_system = molecular_system.combine_with_items(simulation_to_potential_energy_minimization)
        context = convert(molecular_system, selection=selection, syntaxis=syntaxis, to_form='openmm.Context')
        state = context.getState(getEnergy=True)
        output = state.getPotentialEnergy()

    else:

        raise NotImplementedError()

    output = puw.standardize(output)

    return output
Esempio n. 3
0
def mutate(molecular_system,
           residue_indices=None,
           to_residue_names=None,
           engine='PDBFixer',
           verbose=False):

    if engine == "PDBFixer":

        from molsysmt.basic import get, convert, get_form

        if not hasattr(residue_indices, '__iter__'):
            residue_indices = [residue_indices]
        if not hasattr(to_residue_names, '__iter__'):
            to_residue_names = [to_residue_names]

        to_residue_names = [name.upper() for name in to_residue_names]

        form_in = get_form(molecular_system)
        tmp_molecular_system = convert(molecular_system,
                                       to_form="pdbfixer.PDBFixer")

        from_residue_names, residue_ids, in_chain_ids = get(
            tmp_molecular_system,
            target='group',
            indices=residue_indices,
            group_name=True,
            group_id=True,
            chain_id=True)

        for residue_id, from_residue_name, to_residue_name, in_chain_id in zip(
                residue_ids, from_residue_names, to_residue_names,
                in_chain_ids):
            mutation_string = "-".join(
                [from_residue_name,
                 str(residue_id), to_residue_name])
            if verbose: print(mutation_string)
            tmp_molecular_system.applyMutations([mutation_string], in_chain_id)

        tmp_molecular_system = convert(tmp_molecular_system, to_form=form_in)

        return tmp_molecular_system

    else:
        raise NotImplementedError
Esempio n. 4
0
def to_molsysmt_MolSys(item, selection='all', structure_indices='all', syntaxis='MolSysMT'):

    from molsysmt.tools.file_trjpk import is_file_trjpk
    from molsysmt.basic import convert

    if not is_file_trjpk(item):
        raise ValueError

    tmp_item = convert(item, 'molsysmt.MolSys', selection=selection, structure_indices=structure_indices, syntaxis=syntaxis)

    return tmp_item
Esempio n. 5
0
def to_molsysmt_MolSys(item, selection='all', structure_indices='all', syntaxis='MolSysMT'):

    from molsysmt.tools.string_smiles import is_string_smiles
    from molsysmt.basic import convert

    if not is_string_smiles(item):
        raise ValueError

    tmp_item = convert(item, to_form='molsysmt.MolSys', selection=selection, structure_indices=structure_indices, syntaxis=syntaxis)

    return tmp_item
Esempio n. 6
0
def to_openmm_Simulation(item,
                         molecular_system=None,
                         atom_indices='all',
                         structure_indices='all'):

    from molsysmt.basic import convert, get
    from openmm.app import Simulation

    topology = convert(molecular_system,
                       to_form='openmm.Topology',
                       selection=atom_indices)
    positions = get(molecular_system,
                    target='atom',
                    selection=atom_indices,
                    structure_indices=structure_indices,
                    coordinates=True)
    positions = puw.convert(positions[0], to_unit='nm', to_form='openmm.unit')
    simulation = convert(molecular_system, to_form='molsysmt.Simulation')

    integrator = simulation.to_openmm_Integrator()
    platform = simulation.to_openmm_Platform()

    properties = simulation.get_openmm_Simulation_parameters()

    tmp_item = Simulation(topology, item, integrator, platform, properties)
    tmp_item.context.setPositions(positions)
    if simulation.initial_velocities_to_temperature:
        temperature = puw.convert(simulation.temperature,
                                  to_unit='K',
                                  to_form='openmm.unit')
        tmp_item.context.setVelocitiesToTemperature(temperature)

    if molecular_system is not None:
        tmp_molecular_system = molecular_system.combine_with_items(
            tmp_item,
            atom_indices=atom_indices,
            structure_indices=structure_indices)
    else:
        tmp_molecular_system = None

    return tmp_item, tmp_molecular_system
Esempio n. 7
0
def to_nglview_NGLWidget(item, selection='all', structure_indices='all', syntaxis='MolSysMT'):

    from molsysmt.tools.aminoacids3 import is_string_aminoacids3
    from molsysmt.basic import convert

    if not is_string_aminoacids3(item):
        raise ValueError

    tmp_item = convert(item, to_form='nglview.NGLWidget', selection=selection,
            structure_indices=structure_indices, syntaxis=syntaxis)

    return tmp_item
Esempio n. 8
0
def to_molsysmt_Structures(item, selection='all', structure_indices='all', syntaxis='MolSysMT'):

    from molsysmt.tools.rdkit_Mol import is_rdkit_Mol
    from molsysmt.basic import convert

    if not is_rdkit_Mol(item):
        raise ValueError

    tmp_item = convert(item, to_form='molsysmt.Trajectory', selection=selection,
            structure_indices=structure_indices, syntaxis=syntaxis)

    return tmp_item
Esempio n. 9
0
def to_mdtraj_Topology(item, selection='all', structure_indices='all', syntaxis='MolSysMT'):

    from molsysmt.tools.parmed_GromacsTopologyFile import is_parmed_GromacsTopologyFile
    from molsysmt.basic import convert

    if not is_parmed_GromacsTopologyFile(item):
        raise ValueError

    tmp_item = convert(item, to_form='mdtraj_Topology', selection=selection,
            structure_indices=structure_indices, syntaxis=syntaxis)

    return tmp_item
Esempio n. 10
0
def to_file_top(item, selection='all', structure_indices='all', output_filename=None, syntaxis='MolSysMT'):

    from molsysmt.tools.molsysmt_MolSys import is_molsymst_MolSys
    from molsysmt.basic import convert

    if not is_molsysmt_MolSys(item):
        raise ValueError

    if output_filename is None:
        raise ValueError

    tmp_item = convert(item, to_form=output_filename, selection=selection,
            structure_indices=structure_indices, syntaxis=syntaxis)

    return tmp_item
Esempio n. 11
0
def to_file_fasta(item, selection='all', structure_indices='all', output_filename=None, syntaxis='MolSysMT'):

    from molsysmt.tools.string_aminoacids1 import is_string_aminoacids1
    from molsysmt.basic import convert

    if not is_string_aminoacids1(item):
        raise ValueError

    if output_filename is None:
        raise ValueError

    tmp_item = convert(item, to_form=output_filename, selection=selection,
            structure_indices=structure_indices, syntaxis=syntaxis)

    return tmp_item
Esempio n. 12
0
def to_biopython_SeqRecord(item,
                           selection='all',
                           structure_indices='all',
                           syntaxis='MolSysMT'):

    from molsysmt.tools.file_fasta import is_file_fasta
    from molsysmt.basic import convert

    if not is_file_fasta(item):
        raise ValueError

    tmp_item = convert(item,
                       'biopython.SeqRecord',
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 13
0
def to_openmm_Topology(item,
                       selection='all',
                       structure_indices='all',
                       syntaxis='MolSysMT'):

    from molsysmt.tools.file_top import is_file_top
    from molsysmt.basic import convert

    if not is_file_top(item):
        raise ValueError

    tmp_item = convert(item,
                       'openmm.Topology',
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 14
0
def to_molsysmt_Topology(item,
                         selection='all',
                         structure_indices='all',
                         syntaxis='MolSysMT'):

    from molsysmt.tools.openff_Molecule import is_openff_Molecule
    from molsysmt.basic import convert

    if not is_openff_Molecule(item):
        raise ValueError

    tmp_item = convert(item,
                       to_form='molsysmt.Topology',
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 15
0
def to_molsysmt_Simulation(item,
                           selection='all',
                           structure_indices='all',
                           syntaxis='MolSysMT'):

    from molsysmt.tools.molsysmt_SimulationDict import is_molsysmt_SimulationDict
    from molsysmt.basic import convert

    if not is_molsysmt_SimulationDict(item):
        raise ValueError

    tmp_item = convert(item,
                       to_form='molsysmt.Simulation',
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 16
0
def to_XYZ(item,
           selection='all',
           structure_indices='all',
           syntaxis='MolSysMT'):

    from molsysmt.tools.file_xyznpy import is_file_xyznpy
    from molsysmt.basic import convert

    if not is_file_xyznpy(item):
        raise ValueError

    tmp_item = convert(item,
                       'XYZ',
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 17
0
def to_molsysmt_Structures(item,
                           selection='all',
                           structure_indices='all',
                           syntaxis='MolSysMT'):

    from molsysmt.tools.file_mdcrd import is_file_mdcrd
    from molsysmt.basic import convert

    if not is_file_mdcrd(item):
        raise ValueError

    tmp_item = convert(item,
                       'molsysmt.Trajectory',
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 18
0
def to_biopython_Seq(item,
                     selection='all',
                     structure_indices='all',
                     syntaxis='MolSysMT'):

    from molsysmt.tools.aminoacids3 import is_string_aminoacids3
    from molsysmt.basic import convert

    if not is_string_aminoacids3(item):
        raise ValueError

    tmp_item = convert(item,
                       to_form='biopython.Seq',
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 19
0
def to_openmm_Context(item,
                      selection='all',
                      structure_indices='all',
                      syntaxis='MolSysMT'):

    from molsysmt.tools.openmm_Simulation import is_openmm_Simulation
    from molsysmt.basic import convert

    if not is_openmm_Simulation(item):
        raise ValueError

    tmp_item = convert(item,
                       to_form='openmm.Context',
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 20
0
def to_parmed_Structure(item,
                        selection='all',
                        structure_indices='all',
                        syntaxis='MolSysMT'):

    from molsysmt.tools.file_top import is_file_top
    from molsysmt.basic import convert

    if not is_file_top(item):
        raise ValueError

    tmp_item = convert(item,
                       'parmed.Structure',
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 21
0
def get_missing_heavy_atoms(molecular_system,
                            selection='all',
                            engine='PDBFixer',
                            syntaxis='MolSysMT'):

    engine = digest_engine(engine)

    output = {}

    if engine == "PDBFixer":

        from molsysmt.basic import convert, get_form, select

        correction_group_indices = False
        if selection is not 'all':
            group_indices_in_selection = select(molecular_system,
                                                target='group',
                                                selection=selection)
            correction_group_indices = True

        tmp_item = convert(molecular_system,
                           selection=selection,
                           to_form="pdbfixer.PDBFixer",
                           syntaxis=syntaxis)

        tmp_item.findMissingResidues()
        tmp_item.findMissingAtoms()
        missingAtoms = tmp_item.missingAtoms

        for group, atoms in missingAtoms.items():
            if correction_group_indices:
                group_index = group_indices_in_selection[group.index]
            else:
                group_index = group.index
            output[group_index] = []
            for atom in atoms:
                output[group_index].append(atom.name)

    else:

        raise NotImplementedError

    return output
Esempio n. 22
0
    def to_openmm_System(self,
                         molecular_system=None,
                         selection='all',
                         structure_indices='all'):

        from molsysmt.basic import convert

        if molecular_system is None:
            molecular_system = self._molecular_system
        else:
            molecular_system = digest_molecular_system(molecular_system)

        if molecular_system is None:
            raise NoMolecularSystemError()

        system = convert([molecular_system, self],
                         selection=selection,
                         to_form='openmm.System')

        return system
Esempio n. 23
0
def get_sasa (molecular_system, target='atom', selection='all', structure_indices='all', syntaxis='MolSysMT',
          engine='MDTraj'):

    engine = digest_engine(engine)
    target = digest_target(target)

    if engine == 'MDTraj':

        from mdtraj import shrake_rupley

        tmp_item = convert(molecular_system, structure_indices=structure_indices, to_form='mdtraj.Trajectory')

        sasa_array = shrake_rupley(tmp_item, mode='atom') # tiene probe_radius y n_sphere_points

        if target=='atom':

            if selection is not 'all':

                atom_indices = select(molecular_system, selection=selection, syntaxis=syntaxis)
                sasa_array = sasa_array[:,atom_indices]

        else:

            sets_atoms = get(molecular_system, target=target, selection=selection, syntaxis=syntaxis, atom_index=True)

            n_sets = len(sets_atoms)
            n_structures = sasa_array.shape[0]

            new_sasa_array = np.empty([n_structures, n_sets], dtype='float')
            for ii in range(n_sets):
                new_sasa_array[:,ii] = sasa_array[:,sets_atoms[ii].astype(int)].sum(axis=1)
            sasa_array = new_sasa_array

        sasa_array = puw.quantity(sasa_array, 'nm**2')
        sasa_array = puw.standardize(sasa_array)

    else:

        raise NotImplementedError("Engine not implemented yet")

    return sasa_array
Esempio n. 24
0
    def to_openmm_Context(self,
                          molecular_system=None,
                          selection='all',
                          structure_indices='all'):

        from molsysmt.basic import convert

        if molecular_system is None:
            molecular_system = self._molecular_system
        else:
            molecular_system = digest_molecular_system(molecular_system)

        if molecular_system is None:
            raise NoMolecularSystemError()

        context = convert(molecular_system,
                          selection=selection,
                          simulation=self,
                          to_form='openmm.Context')

        return context
Esempio n. 25
0
def to_openmm_Simulation(item,
                         molecular_system,
                         atom_indices='all',
                         structure_indices='all'):

    from molsysmt.form.openmm_Topology import to_openmm_Simulation as openmm_Topology_to_openmm_Simulation
    from molsysmt.basic import convert

    molecular_mechanics = convert(molecular_system,
                                  to_form='molsysmt.MolecularMechanics')

    forcefield = molecular_mechanics.to_openmm_ForceField()
    system_parameters = molecular_mechanics.get_openmm_System_parameters()

    tmp_item = openmm_Topology_to_openmm_Context(item,
                                                 atom_indices=atom_indices,
                                                 forcefield=forcefield,
                                                 parameters=parameters,
                                                 check=False)

    return tmp_item
Esempio n. 26
0
def one_system(molecular_system=None,
               selection=None,
               structure_indices=None,
               form=None,
               syntaxis='MolSysMT'):

    from molsysmt.basic import convert, select

    atom_indices = None

    if form is not None:
        tmp_molecular_system = convert(molecular_system, form)
    else:
        tmp_molecular_system = item

    if selection is not None:
        atom_indices = select(molecular_system, selection, syntaxis=syntaxis)

    structure_indices = frameslist(tmp_molecular_system, structure_indices)

    return tmp_molecular_system, atom_indices, structure_indices
Esempio n. 27
0
def to_file_pir(item,
                selection='all',
                structure_indices='all',
                output_filename=None,
                syntaxis='MolSysMT'):

    from molsysmt.tools.biopython_SeqRecord import is_biopython_SeqRecord
    from molsysmt.basic import convert

    if not is_biopython_SeqRecord(item):
        raise ValueError

    if output_filename is None:
        raise ValueError

    tmp_item = convert(item,
                       to_form=output_filename,
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 28
0
def to_file_pdb(item,
                selection='all',
                structure_indices='all',
                output_filename=None,
                syntaxis='MolSysMT'):

    from molsysmt.tools.openmm_Simulation import is_openmm_Simulation
    from molsysmt.basic import convert

    if not is_openmm_Simulation(item):
        raise ValueError

    if output_filename is None:
        raise ValueError

    tmp_item = convert(item,
                       to_form=output_filename,
                       selection=selection,
                       structure_indices=structure_indices,
                       syntaxis=syntaxis)

    return tmp_item
Esempio n. 29
0
def add_terminal_cappings(molecular_system,
                          N_terminal=None,
                          C_terminal=None,
                          selection='all',
                          syntaxis='MolSysMT',
                          engine='PDBFixer'):

    from molsysmt.basic import get_form, convert, get, select

    form_in = get_form(molecular_system)

    if engine is 'PDBFixer':

        from pdbfixer.pdbfixer import Sequence

        tmp_molecular_system = convert(molecular_system,
                                       to_form='pdbfixer.PDBFixer')
        atom_indices_in_selection = select(tmp_molecular_system,
                                           selection=selection,
                                           syntaxis=syntaxis)
        atom_indices_in_components = get(
            tmp_molecular_system,
            target='component',
            selection='component_type in ["peptide", "protein"] \
                                         and atom_index in @atom_indices_in_selection',
            atom_index=True)

        for atom_indices_in_component in atom_indices_in_components:

            chain_id = get(
                tmp_molecular_system,
                target='chain',
                selection='atom_index in @atom_indices_in_component',
                chain_id=True)
            groups_sequence = get(
                tmp_molecular_system,
                target='group',
                selection='atom_index in @atom_indices_in_component',
                group_name=True)

            groups_sequence = list(groups_sequence)

            if N_terminal is not None:

                groups_sequence = [N_terminal] + groups_sequence

            if C_terminal is not None:

                groups_sequence = groups_sequence + [C_terminal]

            tmp_molecular_system.sequences.append(
                Sequence(chain_id, groups_sequence))

        tmp_molecular_system.findMissingResidues()
        tmp_molecular_system.findMissingAtoms()
        tmp_molecular_system.addMissingAtoms()

        n_hs = get(tmp_molecular_system,
                   target='atom',
                   selection='atom_type=="H"',
                   n_atoms=True)

        if n_hs > 0:

            tmp_molecular_system.addMissingHydrogens(pH=7.4)

        tmp_molecular_system = convert(tmp_molecular_system, to_form=form_in)

    else:

        raise NotImplementedError

    return tmp_molecular_system
Esempio n. 30
0
def get_sequence_alignment(molecular_system,
                           selection='all',
                           reference_molecular_system=None,
                           reference_selection=None,
                           engine='biopython',
                           syntaxis='MolSysMT',
                           prettyprint=False,
                           alignment_index=0):

    if engine == 'biopython':

        # from ensembler.modeling.align_target_template
        # (https://github.com/choderalab/ensembler/blob/master/ensembler/modeling.py)

        # See: https://biopython.org/docs/1.75/api/Bio.Align.html#Bio.Align.PairwiseAligner

        from Bio import Align
        tmp_ref_seq = convert(reference_molecular_system,
                              selection=reference_selection,
                              syntaxis=syntaxis,
                              to_form='biopython.Seq')
        tmp_seq = convert(molecular_system,
                          selection=selection,
                          syntaxis=syntaxis,
                          to_form='biopython.Seq')
        aligner = Align.PairwiseAligner()
        aligner.mode = 'global'
        aligner.match_score = 1.0
        aligner.mismatch_score = 0.0
        aligner.open_gap_score = -0.5
        aligner.extend_gap_score = -0.1
        aligner.target_end_gap_score = 0.0
        aligner.query_end_gap_score = 0.0
        alignment = aligner.align(tmp_ref_seq, tmp_seq)
        del (aligner, Align, tmp_ref_seq, tmp_seq)

        txt_aln = alignment[alignment_index].format().split('\n')
        seq_ref = txt_aln[0]
        seq = txt_aln[2]

    elif engine == 'modeller':

        raise NotImplementedError

    else:

        raise NotImplementedError

    if prettyprint:

        textredbold = '\033[1;31;48m'  # Red bold text
        textbluebold = '\033[1;34;48m'  # Green bold text
        endcolor = '\033[m'  # reset color
        # Color guide in: http://ozzmaker.com/add-colour-to-text-in-python/

        pptxt = ''
        pptxt_ref = ''

        for res, res_ref in zip(seq, seq_ref):
            if res == res_ref:
                pptxt += res
                pptxt_ref += res_ref
            elif (res == '-' and res_ref != '-'):
                pptxt += res
                pptxt_ref += textbluebold + res_ref + endcolor
            elif (res_ref == '-' and res != '-'):
                pptxt += textbluebold + res + endcolor
                pptxt_ref += res_ref
            else:
                pptxt += textredbold + res + endcolor
                pptxt_ref += textredbold + res_ref + endcolor

        print(pptxt)
        print()
        print(pptxt_ref)

        pass

    else:

        return seq, seq_ref