Esempio n. 1
0
def set_coordinates_to_atom(item, indices='all', structure_indices='all', value=None, check=True):

    if check:

        _digest_item(item, 'molsysmt.MolSys')
        indices = _digest_indices(indices)
        structure_indices = _digest_structure_indices(structure_indices)

    value = _puw.standardize(value)

    if indices is 'all':
        if item.structures.coordinates.shape[1]!=value.shape[1]:
            raise ValueError('New coordinates array has different number of atoms')

    if structure_indices is 'all':
        if item.structures.coordinates.shape[0]!=value.shape[0]:
            raise ValueError('New coordinates array has different number of frames')

    if indices is 'all':
        if structure_indices is 'all':
            item.structures.coordinates[:,:,:] = value[:,:,:]
        else:
            item.structures.coordinates[structure_indices,:,:] = value[:,:,:]
    else:
        if structure_indices is 'all':
            item.structures.coordinates[:,indices,:] = value[:,:,:]
        else:
            item.structures.coordinates[_np.ix_(structure_indices, indices)]=value[:,:,:]
Esempio n. 2
0
def get_coordinates_from_atom(item,
                              indices='all',
                              structure_indices='all',
                              check=True):

    if check:

        _digest_item(item, _form)
        indices = _digest_indices(indices)
        structure_indices = _digest_structure_indices(structure_indices)

    unit = _puw.get_unit(item.positions)
    coordinates = _np.array(_puw.get_value(item.positions))
    coordinates = coordinates.reshape(1, coordinates.shape[0],
                                      coordinates.shape[1])

    if structure_indices is not 'all':
        coordinates = coordinates[structure_indices, :, :]

    if indices is not 'all':
        coordinates = coordinates[:, indices, :]

    coordinates = coordinates * unit
    coordinates = _puw.standardize(coordinates)

    return coordinates
Esempio n. 3
0
def get_coordinates_from_atom(item,
                              indices='all',
                              structure_indices='all',
                              check=True):

    if check:

        _digest_item(item, _form)
        indices = _digest_indices(indices)
        structure_indices = _digest_structure_indices(structure_indices)

    xyz = item.getPositions(asNumpy=True)

    unit = _puw.get_unit(xyz)

    xyz = _np.expand_dims(xyz, axis=0)

    if structure_indices is not 'all':
        xyz = xyz[structure_indices, :, :]
    if indices is not 'all':
        xyz = xyz[:, indices, :]

    xyz = _puw.standardize(xyz * unit)

    return xyz
Esempio n. 4
0
def get_box_from_system(item, structure_indices='all', check=True):

    if check:

        _digest_item(item, _form)
        structure_indices = _digest_structure_indices(structure_indices)

    from molsysmt._private.math import serie_to_chunks

    if structure_indices is 'all':

        n_structures = get_n_structures_from_system(item)
        structure_indices = np.arange(n_structures)

    starts_serie_frames, size_serie_frames = serie_to_chunks(structure_indices)

    box_list = []

    for start, size in zip(starts_serie_frames, size_serie_frames):
        item.seek(start)
        _, _, _, box = item.read(n_frames=size)
        box_list.append(box)

    box = np.concatenate(box_list)
    del (box_list)

    box = box.astype('float64')

    box = box * _puw.unit(item.distance_unit)
    box = _puw.standardize(box)

    return box
Esempio n. 5
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. 6
0
def get_box_from_system(item, structure_indices='all', check=True):

    if check:

        _digest_item(item, _form)
        structure_indices = _digest_structure_indices(structure_indices)

    from molsysmt.pbc import box_vectors_from_box_lengths_and_angles

    n_structures = get_n_structures_from_system(item, check=False)

    if item.unit_cell is not None:

        cell_lengths = _np.empty([n_structures,3], dtype='float64')
        cell_angles = _np.empty([n_structures,3], dtype='float64')
        for ii in range(3):
            cell_lengths[:,ii] = item.unit_cell[ii]
            cell_angles[:,ii] = item.unit_cell[ii+3]

        cell_lengths = _puw.quantity(cell_lengths, 'angstroms')
        cell_angles = _puw.quantity(cell_angles, 'degrees')

        box = box_vectors_from_box_lengths_and_angles(cell_lengths, cell_angles)
        box = _puw.standardize(box)

    else:

        box = None

    if structure_indices is not 'all':
        if box is not None:
            box = box[structure_indices,:,:]

    return box
Esempio n. 7
0
def get_box_from_system(item, structure_indices='all', check=True):

    if check:

        _digest_item(item, _form)
        structure_indices = _digest_structure_indices(structure_indices)

    from molsysmt._private.math import serie_to_chunks
    from molsysmt.pbc import box_vectors_from_box_lengths_and_angles

    if structure_indices is 'all':
        structure_indices = _np.arange(get_n_structures_from_system(item))

    starts_serie_frames, size_serie_frames = serie_to_chunks(structure_indices)

    box_list = []

    for start, size in zip(starts_serie_frames, size_serie_frames):
        item.seek(start)
        frame_hdf5 = item.read(n_frames=size)
        cell_lengths = frame_hdf5.cell_lengths
        cell_angles = frame_hdf5.cell_angles
        box = box_vectors_from_box_lengths_and_angles(
            cell_lengths * _puw.unit('nm'), cell_angles * _puw.unit('degrees'))
        box_list.append(_puw.get_value(box))

    box = _np.concatenate(box_list)
    del (box_list)

    box = box.astype('float64')

    box = box * _puw.unit('nm')
    box = _puw.standardize(box)

    return box
Esempio n. 8
0
def get_time_from_system(item, structure_indices='all', check=True):

    if check:

        _digest_item(item, _form)
        structure_indices = _digest_structure_indices(structure_indices)

    from molsysmt._private.math import serie_to_chunks

    if structure_indices is 'all':

        n_structures = get_n_structures_from_system(item)
        structure_indices = np.arange(n_structures)

    starts_serie_frames, size_serie_frames = serie_to_chunks(structure_indices)

    time_list = []

    for start, size in zip(starts_serie_frames, size_serie_frames):
        item.seek(start)
        _, time, _, _ = item.read(n_frames=size)
        time_list.append(time)

    time = _np.concatenate(time_list)
    del (time_list)

    time = time.astype('float64')

    time = time * _puw.unit('ps')
    time = _puw.standardize(time)

    return time
Esempio n. 9
0
def get_time_from_system(item, indices='all', structure_indices='all'):

    output = item.getState().getTime()
    value = puw.get_value(output)
    unit = puw.get_unit(output)
    output = np.array([value]) * unit
    output = puw.standardize(output)

    return output
Esempio n. 10
0
    def set_parameters(self, return_non_processed=False, **kwargs):

        for argument, value in kwargs.items():
            if argument.lower() in self.__dict__.keys():
                self.__dict__[argument] = puw.standardize(value)
                del (kwargs[argment.lower()])

        if return_non_processed:
            return kwargs
        else:
            pass
Esempio n. 11
0
def get_time_from_system(item, indices='all', structure_indices='all'):

    _, time, _, _ = item.read()

    time = time*puw.unit('ps')

    if structure_indices is not 'all':
        time = time[structure_indices]*picoseconds

    time = puw.standardize(time)

    return time
Esempio n. 12
0
def get_box_from_system(item, structure_indices='all', check=True):

    if check:

        _digest_item(item, _form)
        structure_indices = _digest_structure_indices(structure_indices)

    box = item.getPeriodicBoxVectors()
    unit = _puw.get_unit(box)
    box = _np.expand_dims(puw.get_value(box), axis=0)
    box = _puw.standardize(box * unit)

    return box
Esempio n. 13
0
def get_box_from_system(item, structure_indices='all', check=True):

    if check:

        _digest_item(item, _form)
        structure_indices = _digest_structure_indices(structure_indices)

    box = getBoxVectors(asNumpy=True)
    unit = _puw.get_unit(box)
    box = _np.expand_dims(box, axis=0)
    box = _puw.standardize(box * unit)

    return box
def get_coordinates_from_atom(item, indices='all', structure_indices='all'):

    xyz = item.positions

    if structure_indices is not 'all':
        xyz = xyz[structure_indices, :, :]
    if indices is not 'all':
        xyz = xyz[:, indices, :]

    xyz = xyz * puw.unit(item.distance_unit)
    xyz = puw.standardize(xyz)

    return xyz
Esempio n. 15
0
def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', check=True):

    if check:

        digest_item(item, 'file:msmpk')
        atom_indices = digest_atom_indices(atom_indices)
        structure_indices = digest_structure_indices(structure_indices)

    from ..molsysmt_MolSys import extract as extract_molsysmt_MolSys
    from molsysmt import puw
    import pickle

    fff = open(item,'rb')
    tmp_item = pickle.load(fff)
    fff.close()

    # lengths with nm values and time in ps

    if tmp_item.structures.coordinates is not None:
        value = tmp_item.structures.coordinates
        quantity = puw.quantity(value, 'nm')
        tmp_item.structures.coordinates = puw.standardize(quantity)

    if tmp_item.structures.box is not None:
        value = tmp_item.structures.box
        quantity = puw.quantity(value, 'nm')
        tmp_item.structures.box = puw.standardize(quantity)

    if tmp_item.structures.time is not None:
        value = tmp_item.structures.time
        quantity = puw.quantity(value, 'ps')
        tmp_item.structures.time = puw.standardize(quantity)

    tmp_item = extract_molsysmt_MolSys(tmp_item, atom_indices=atom_indices,
            structure_indices=structure_indices, copy_if_all=False, check=False)

    return tmp_item
def get_box_lengths_from_system(item, indices='all', structure_indices='all'):

    cell_lengths = item.unitcell_lengths

    if cell_lengths is not None:

        cell_lengths = cell_lengths * puw.unit(item.distance_unit)
        if structure_indices is not 'all':
            cell_lengths = cell_lengths[structure_indices]
        cell_lengths = puw.standardize(cell_lengths)

    else:

        cell_lengths = None

    return cell_lengths
def get_box_angles_from_system(item, indices='all', structure_indices='all'):

    cell_angles = item.unitcell_angles

    if cell_lengths is not None:

        cell_angles = cell_angles * puw.unit('degrees')
        if structure_indices is not 'all':
            cell_angles = cell_angles[structure_indices]
        cell_angles = puw.standardize(cell_angles)

    else:

        cell_angles = None

    return cell_angles
Esempio n. 18
0
def get_coordinates_from_atom(item, indices='all', structure_indices='all'):

    unit = puw.get_unit(item.positions)
    coordinates = np.array(puw.get_value(item.positions))
    coordinates = coordinates.reshape(1, coordinates.shape[0],
                                      coordinates.shape[1])

    if structure_indices is not 'all':
        coordinates = coordinates[structure_indices, :, :]

    if indices is not 'all':
        coordinates = coordinates[:, indices, :]

    coordinates = coordinates * unit
    coordinates = puw.standardize(coordinates)

    return coordinates
Esempio n. 19
0
def get_coordinates_from_atom(item, indices='all', structure_indices='all'):

    coordinates = item.getState(getPositions=True).getPositions(asNumpy=True)
    unit = puw.get_unit(coordinates)
    coordinates = puw.get_value(coordinates)
    coordinates = coordinates.reshape(1, coordinates.shape[0],
                                      coordinates.shape[1])

    if structure_indices is not 'all':
        coordinates = coordinates[structure_indices, :, :]

    if indices is not 'all':
        coordinates = coordinates[:, indices, :]

    coordinates = coordinates * unit
    coordinates = puw.standardize(coordinates)

    return coordinates
Esempio n. 20
0
def get_coordinates_from_atom(item, indices='all', structure_indices='all', check=True):

    if check:

        _digest_item(item, _form)
        indices = _digest_indices(indices)

    xyz = _np.column_stack([item.x_coord_list, item.y_coord_list, item.z_coord_list])
    xyz = xyz.reshape([-1, item.num_atoms, 3])
    xyz = _puw.quantity(xyz, 'angstroms')
    xyz = _puw.standardize(xyz)

    if structure_indices is not 'all':
        xyz = xyz[structure_indices,:,:]

    if indices is not 'all':
        xyz = xyz[:,indices,:]

    return xyz
Esempio n. 21
0
def get_box_from_system(item, structure_indices='all', check=True):

    if check:

        _digest_item(item, _form)
        structure_indices = _digest_structure_indices(structure_indices)

    box = item.getPeriodicBoxVectors()

    output = None

    if box is not None:
        unit = _puw.get_unit(box)
        box = _np.array(_puw.get_value(box))
        box = box.reshape(1, box.shape[0], box.shape[1])
        box = box * unit
        output = _puw.standardize(box)

    return output
Esempio n. 22
0
def get_box_from_system(item, indices='all', structure_indices='all'):

    from molsysmt.pbc import box_vectors_from_box_lengths_and_angles

    _, _, cell_lengths, cell_angles = item.read()

    if cell_lengths is not None:

        cell_lengths = cell_lengths*puw.unit(item.distance_unit)
        cell_angles = cell_angles*puw.unit('degrees')
        box = box_vectors_from_box_lengths_and_angles(cell_lengths, cell_angles)
        if structure_indices is not 'all':
            box = box[structure_indices,:,:]
        box = puw.standardize(box)

    else:

        box = None

    return box
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 get_coordinates_from_atom(item,
                              indices='all',
                              structure_indices='all',
                              check=True):

    if check:

        _digest_item(item, _form)
        indices = _digest_indices(indices)
        structure_indices = _digest_structure_indices(structure_indices)

    from molsysmt._private.math import serie_to_chunks

    if structure_indices is 'all':

        n_structures = get_n_structures_from_system(item)
        structure_indices = _np.arange(n_structures)

    starts_serie_frames, size_serie_frames = serie_to_chunks(structure_indices)

    xyz_list = []

    for start, size in zip(starts_serie_frames, size_serie_frames):
        item.seek(start)
        if indices is 'all':
            xyz, _, _, _ = item.read(n_structures=size)
        else:
            xyz, _, _, _ = item.read(n_structures=size, atom_indices=indices)
        xyz_list.append(xyz)

    xyz = _np.concatenate(xyz_list)
    del (xyz_list)

    xyz = xyz.astype('float64')

    xyz = xyz * _puw.unit(item.distance_unit)
    xyz = _puw.standardize(xyz)

    return xyz
Esempio n. 25
0
def get_least_rmsd(molecular_system=None,
                   selection='backbone',
                   structure_indices='all',
                   reference_molecular_system=None,
                   reference_selection=None,
                   reference_frame_index=0,
                   reference_coordinates=None,
                   parallel=True,
                   syntaxis='MolSysMT',
                   engine='MolSysMT',
                   check=True):

    if check:
        from molsysmt.tools.molecular_system import is_molecular_system
        if not is_a_molecular_system(molecular_system):
            raise SingleMolecularSystemNeededError()

    engine = digest_engine(engine)

    if engine == 'MolSysMT':

        n_atoms, n_structures = get(molecular_system,
                                    n_atoms=True,
                                    n_structures=True,
                                    check=False)
        atom_indices = select(molecular_system,
                              selection=selection,
                              syntaxis=syntaxis,
                              check=False)
        n_atom_indices = atom_indices.shape[0]
        structure_indices = digest_structure_indices(structure_indices)
        if structure_indices is 'all':
            structure_indices = np.arange(n_structures)
        n_structure_indices = structure_indices.shape[0]

        if reference_coordinates is None:

            if reference_molecular_system is None:
                reference_molecular_system = molecular_system

            if reference_selection is None:
                reference_selection = selection

            reference_atom_indices = select(reference_molecular_system,
                                            selection=reference_selection,
                                            syntaxis=syntaxis,
                                            check=False)

            reference_coordinates = get(
                reference_molecular_system,
                target='atom',
                indices=reference_atom_indices,
                structure_indices=reference_frame_index,
                coordinates=True,
                check=False)

        coordinates = get(molecular_system,
                          coordinates=True,
                          structure_indices='all',
                          check=False)
        units = puw.get_unit(coordinates)
        coordinates = np.asfortranarray(puw.get_value(coordinates),
                                        dtype='float64')
        reference_coordinates = np.asfortranarray(puw.get_value(
            reference_coordinates, to_unit=units),
                                                  dtype='float64')

        if reference_coordinates.shape[1] != n_atom_indices:
            raise ValueError(
                "reference selection and selection needs to have the same number of atoms"
            )

        rmsd_val = librmsd.least_rmsd(coordinates, atom_indices,
                                      reference_coordinates, structure_indices,
                                      n_atoms, n_structures, n_atom_indices,
                                      n_structure_indices)

        rmsd_val = rmsd_val * units
        rmsd_val = puw.standardize(rmsd_val)
        del (coordinates, units)
        return rmsd_val

    elif engine == 'MDTraj':

        raise NotImplementedError

    else:
        raise NotImplementedError
Esempio n. 26
0
def energy_minimization (molecular_system, method='L-BFGS', selection='all', syntaxis='MolSysMT', engine='OpenMM', to_form=None, verbose=True):

    """remove(item, selection=None, syntaxis='mdtraj')

    A new structure is returned with the molecular model relaxed to the nearest potential energy local
    minimum.

    Parameters
    ----------
    item : molecular model
        Molecular model in any form to be operated by the method.
    method : str (default "L-BFGS")
        Energy minimization method.
    method : str (default "AMBER99SB-ILDN")
        Forcefield to model the inter-atomic interactions.
    selection : str, int, list, tuple or numpy array (default None)
        Region to be minimized defined as a selection sentence or atoms indices list. By default
        None means all atoms and there by the whole molecular model is minized.
    syntaxis : str (default "mdtraj")
        Name of the selection syntaxis used: "mdtraj" or "amber".
    engine : str (default "openmm")

    Returns
    -------
    item : molecular model
        The result is a new molecular model with coordinates or positions relaxed to the nearest local minimum of
        the potential energy.

    Examples
    --------
    Remove chains 0 and 1 from the pdb: 1B3T.
    >>> import molsysmt as m3t
    >>> system = m3t.load('pdb:1B3T')
    Check the number of chains
    >>> minimized_system = m3t.minimze(system)

    """

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

    engine=digest_engine(engine)
    in_form = get_form(molecular_system)
    if to_form is None:
        to_form = in_form

    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)

        simulation = convert(molecular_system, selection=selection, syntaxis=syntaxis, to_form='openmm.Simulation')

        if verbose:
            state_pre_min = simulation.context.getState(getEnergy=True)
            energy_pre_min = state_pre_min.getPotentialEnergy()
            energy_pre_min = puw.standardize(energy_pre_min)
            print("Potential Energy before minimization: {}".format(energy_pre_min))

        if method=='L-BFGS':
            simulation.minimizeEnergy()

        if verbose:
            state_post_min = simulation.context.getState(getEnergy=True)
            energy_post_min = state_post_min.getPotentialEnergy()
            energy_post_min = puw.standardize(energy_post_min)
            print("Potential Energy after minimization: {}".format(energy_post_min))

        tmp_item = convert(simulation, to_form=to_form)

        return tmp_item

    else:

        raise NotImplementedError
Esempio n. 27
0
def fit(molecular_system=None,
        selection='backbone',
        structure_indices='all',
        reference_molecular_system=None,
        reference_selection=None,
        reference_frame_index=0,
        to_form=None,
        parallel=True,
        syntaxis='MolSysMT',
        method='least rmsd',
        engine='MolSysMT',
        check=True):

    from molsysmt.basic import select, get, set, convert, copy, is_molecular_system

    if check:
        if not is_molecular_system(molecular_system):
            raise MolecularSystemNeededError()

    engine = digest_engine(engine)

    if engine == 'MolSysMT':

        n_atoms, n_structures = get(molecular_system,
                                    n_atoms=True,
                                    n_structures=True,
                                    check=False)
        atom_indices = select(molecular_system,
                              selection=selection,
                              syntaxis=syntaxis,
                              check=False)
        n_atom_indices = atom_indices.shape[0]
        structure_indices = digest_structure_indices(structure_indices)
        if structure_indices is 'all':
            structure_indices = np.arange(n_structures)
        n_structure_indices = structure_indices.shape[0]

        if reference_molecular_system is None:
            reference_molecular_system = molecular_system

        if reference_selection is None:
            reference_selection = selection

        reference_atom_indices = select(reference_molecular_system,
                                        selection=reference_selection,
                                        syntaxis=syntaxis,
                                        check=False)

        reference_coordinates = get(reference_molecular_system,
                                    target='atom',
                                    indices=reference_atom_indices,
                                    structure_indices=reference_frame_index,
                                    coordinates=True,
                                    check=False)

        coordinates = get(molecular_system,
                          coordinates=True,
                          structure_indices='all',
                          check=False)
        units = puw.get_unit(coordinates)
        coordinates = np.asfortranarray(puw.get_value(coordinates),
                                        dtype='float64')
        reference_coordinates = np.asfortranarray(puw.get_value(
            reference_coordinates, to_unit=units),
                                                  dtype='float64')

        if reference_coordinates.shape[1] != n_atom_indices:
            raise ValueError(
                "reference selection and selection needs to have the same number of atoms"
            )

        librmsd.least_rmsd_fit(coordinates, atom_indices,
                               reference_coordinates, structure_indices,
                               n_atoms, n_structures, n_atom_indices,
                               n_structure_indices)

        coordinates = np.ascontiguousarray(coordinates) * units
        coordinates = puw.standardize(coordinates)

        if to_form is None:
            tmp_molecular_system = copy(molecular_system, check=False)
        else:
            tmp_molecular_system = convert(molecular_system,
                                           to_form=to_form,
                                           check=False)

        set(tmp_molecular_system,
            target='system',
            coordinates=coordinates,
            check=False)
        del (coordinates, units)
        return tmp_molecular_system

    elif engine == 'MDTraj':

        #tmp_item.superpose(tmp_ref_item,frame=ref_structure_indices,atom_indices=atom_indices,ref_atom_indices=ref_atom_indices,parallel=parallel)

        #if in_form==x_form:
        #    item=tmp_item
        #elif in_form=='molsysmt.Trajectory':
        #    item._import_mdtraj_data(tmp_item)
        #elif in_form=='molsysmt.MolSys':
        #    item.trajectory._import_mdtraj_data(tmp_item)
        #else:
        #    item=_convert(tmp_item, to_form=in_form)

        raise NotImplementedMethodError()

    else:

        raise NotImplementedMethodError()
Esempio n. 28
0
def get_rmsd(molecular_system,
             selection='backbone',
             structure_indices='all',
             reference_molecular_system=None,
             reference_selection=None,
             reference_frame_index=0,
             reference_coordinates=None,
             parallel=True,
             syntaxis='MolSysMT',
             engine='MolSysMT'):

    from molsysmt.basic import is_a_molecular_system

    if not is_a_molecular_system(molecular_system):
        raise SingleMolecularSystemNeededError()

    engine = digest_engine(engine)

    if engine == 'MolSysMT':

        from molsysmt.basic import select, get
        from molsysmt._private._digestion import digest_structure_indices

        n_atoms, n_structures = get(molecular_system,
                                    n_atoms=True,
                                    n_structures=True)
        atom_indices = select(molecular_system,
                              selection=selection,
                              syntaxis=syntaxis)
        n_atom_indices = atom_indices.shape[0]
        structure_indices = digest_structure_indices(structure_indices)
        if structure_indices is 'all':
            structure_indices = np.arange(n_structures)
        n_structure_indices = structure_indices.shape[0]

        if reference_coordinates is None:

            if reference_molecular_system is None:
                reference_molecular_system = molecular_system

            if reference_selection is None:
                reference_selection = selection

            reference_atom_indices = select(reference_molecular_system,
                                            selection=reference_selection,
                                            syntaxis=syntaxis)

            reference_coordinates = get(
                reference_molecular_system,
                target='atom',
                indices=reference_atom_indices,
                structure_indices=reference_frame_index,
                coordinates=True)

        coordinates = get(molecular_system,
                          coordinates=True,
                          structure_indices='all')
        units = puw.get_unit(coordinates)
        coordinates = np.asfortranarray(puw.get_value(coordinates),
                                        dtype='float64')
        reference_coordinates = np.asfortranarray(puw.get_value(
            reference_coordinates, to_unit=units),
                                                  dtype='float64')

        if reference_coordinates.shape[1] != n_atom_indices:
            raise ValueError(
                "reference selection and selection needs to have the same number of atoms"
            )

        rmsd_val = librmsd.rmsd(coordinates, atom_indices,
                                reference_coordinates, structure_indices,
                                n_atoms, n_structures, n_atom_indices,
                                n_structure_indices)

        rmsd_val = rmsd_val * units
        rmsd_val = puw.standardize(rmsd_val)
        del (coordinates, units)
        return rmsd_val

    elif engine == 'MDTraj':

        #from mdtraj import rmsd as mdtraj_rmsd
        #from molsysmt.basic import convert

        #tmp_molecular_system = convert(molecular_system, to_form='mdtraj.Trajectory')

        #rmsd_val = mdtraj_rmsd(tmp_molecular_system, ref_item, frame=ref_structure_indices,
        #                        ref_atom_indices=ref_atom_indices, atom_indices=atom_indices,
        #                        parallel=parallel, precentered=precentered)

        #rmsd_val = puw.standardize(rmsd_val)

        #return rmsd_val

        raise NotImplementedError

    else:

        raise NotImplementedError
Esempio n. 29
0
    def append_structures(self,
                          step=None,
                          time=None,
                          coordinates=None,
                          box=None,
                          check=True):

        if step is not None:
            if type(step) not in [list, np.ndarray]:
                step = np.array([step])
            else:
                step = step

        if time is not None:
            time = puw.standardize(time)
        if coordinates is not None:
            coordinates = puw.standardize(coordinates)
        if box is not None:
            box = puw.standardize(box)

        n_structures = coordinates.shape[0]
        n_atoms = coordinates.shape[1]

        if self.n_structures == 0:

            self.coordinates = coordinates
            self.step = step
            self.time = time
            self.box = box
            self.n_structures = n_structures
            self.n_atoms = n_atoms

        else:

            if n_atoms != self.n_atoms:
                raise ValueError(
                    "The coordinates to be appended in the system needs to have the same number of atoms."
                )

            if step is not None:
                if self.step is None:
                    raise ValueError(
                        "The trajectory has no steps to append the new frame.")
                else:
                    self.step = np.concatenate([self.step, step])

            if time is not None:
                if self.time is None:
                    raise ValueError(
                        "The trajectory has no time array to append the new frame."
                    )
                else:
                    self.time = np.concatenate([self.time, time])

            if box is not None:
                if self.box is None:
                    raise ValueError(
                        "The trajectory has no box array to append the new frame."
                    )
                else:
                    self.box = np.concatenate([self.box, box])

            self.coordinates = np.concatenate([self.coordinates, coordinates])

            self.n_structures += n_structures

        pass