コード例 #1
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
コード例 #2
0
def get_frame_from_atom(item, indices='all', structure_indices='all'):

    fff = open(item, 'rb')
    _ = pickle.load(fff)
    _ = pickle.load(fff)
    coordinates = pickle.load(fff)
    box = pickle.load(fff)
    time = pickle.load(fff)
    step = pickle.load(fff)
    fff.close()

    if coordinates is not None:
        if structure_indices is not 'all':
            coordinates = coordinates[structure_indices, :, :]
        if indices is not 'all':
            coordinates = coordinates[:, indices, :]
        coordinates = puw.quantity(coordinates, to_unit='nm')

    if box is not None:
        if structure_indices is not 'all':
            box = box[structure_indices, :, :]
        box = puw.quantity(box, to_unit='nm')

    if time is not None:
        if structure_indices is not 'all':
            time = time[structure_indices]
        time = puw.quantity(time, to_unit='ps')

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

    return step, time, coordinates, box
コード例 #3
0
def to_molsysmt_TrajectoryDict(item,
                               molecular_system=None,
                               atom_indices='all',
                               structure_indices='all'):

    tmp_item = {}

    fff = open(item, 'rb')
    _ = pickle.load(fff)
    _ = pickle.load(fff)
    coordinates = pickle.load(fff)
    box = pickle.load(fff)
    time = pickle.load(fff)
    step = pickle.load(fff)
    fff.close()

    if coordinates is not None:
        if structure_indices is not 'all':
            coordinates = coordinates[structure_indices, :, :]
        if atom_indices is not 'all':
            coordinates = coordinates[:, atom_indices, :]
        coordinates = puw.quantity(coordinates, unit='nm')

    if box is not None:
        if structure_indices is not 'all':
            box = box[structure_indices, :, :]
        box = puw.quantity(box, unit='nm')

    if time is not None:
        if structure_indices is not 'all':
            time = time[structure_indices]
        time = puw.quantity(time, unit='ps')

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

    tmp_item['coordinates'] = coordinates
    tmp_item['box'] = box
    tmp_item['time'] = time
    tmp_item['step'] = step

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

    return tmp_item, tmp_molecular_system
コード例 #4
0
def atomic_radius(molecular_system, selection='all', type='vdw'):

    from molsysmt.basic import get
    from molsysmt.physico_chemical_properties.atoms.radius import units
    from molsysmt._private._digestion import digest_target

    if type == 'vdw':
        from molsysmt.physico_chemical_properties.atoms.radius import vdw as values
    else:
        raise NotImplementedError()

    atom_types = get(molecular_system,
                     target='atom',
                     selection=selection,
                     type=True)

    output = []

    for ii in atom_types:
        var_aux = values[ii.capitalize()]
        output.append(var_aux)

    output = puw.quantity(np.array(output), units)

    return output
コード例 #5
0
def box_angles_from_box_vectors(box):

    n_structures = box.shape[0]
    tmp_box = np.asfortranarray(puw.get_value(box), dtype='float64')
    angles = libbox.angles_box(tmp_box, n_structures)
    angles = np.ascontiguousarray(angles, dtype='float64')
    del (tmp_box)

    return puw.quantity(angles.round(6), 'degrees')
コード例 #6
0
ファイル: get.py プロジェクト: uibcdf/MolSysMT
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

    lengths = _puw.quantity(item.unitcells[:,0:3]*0.1, unit='nm')
    angles = _puw.quantity(item.unitcells[:,3:6], unit='degrees')

    if structure_indices is not 'all':
        lengths = lengths[structure_indices,:]
        angles = angles[structure_indices,:]

    output = box_vectors_from_box_lengths_and_angles(lengths, angles)

    return output
コード例 #7
0
ファイル: get.py プロジェクト: uibcdf/MolSysMT
def get_time_from_system(item, structure_indices='all', check=True):

    if check:

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

    output = _puw.quantity(item.time, unit='ps')

    if structure_indices is not 'all':
        output = output[structure_indices]

    return output
コード例 #8
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
コード例 #9
0
def get_box_from_system(item, indices='all', structure_indices='all'):

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

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

        box = puw.quantity(box, to_unit='nm')

    return box
コード例 #10
0
def get_coordinates_from_atom(item, indices='all', structure_indices='all'):

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

    if coordinates is not None:
        if structure_indices is not 'all':
            coordinates = coordinates[structure_indices, :, :]
        if indices is not 'all':
            coordinates = coordinates[:, indices, :]
        coordinates = puw.quantity(coordinates, to_unit='nm')

    return coordinates
コード例 #11
0
ファイル: get.py プロジェクト: uibcdf/MolSysMT
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)

    coordinates= _puw.quantity(item.xyz * 0.1, unit='nm')

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

    return coordinates
コード例 #12
0
def get_time_from_system(item, indices='all', structure_indices='all'):

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

    if time is not None:
        if structure_indices is not 'all':
            time = time[structure_indices]

        time = puw.quantity(time, to_unit='nm')

    return time
コード例 #13
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
コード例 #14
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
コード例 #15
0
ファイル: mass.py プロジェクト: uibcdf/MolSysMT
def mass(molecular_system, target='atom', selection='all'):

    from molsysmt.basic import get
    from molsysmt.physico_chemical_properties.atoms.mass import physical, units
    from molsysmt._private._digestion import digest_target

    target = digest_target(target)

    values = physical

    output = []
    if target == 'atom':
        atom_types = get(molecular_system,
                         target=target,
                         selection=selection,
                         atom_type=True)
        for ii in atom_types:
            output.append(values[ii.capitalize()])
    elif target in ['group', 'component', 'molecule', 'chain', 'entity']:
        atom_types_in_target = get(molecular_system,
                                   target=target,
                                   selection=selection,
                                   atom_type=True)
        for aux in atom_types_in_target:
            output.append(np.sum([values[ii.capitalize()] for ii in aux]))
    elif target == 'system':
        atom_types_in_target = get(molecular_system,
                                   target='atom',
                                   selection='all',
                                   atom_type=True)
        output.append(
            np.sum([values[ii.capitalize()] for ii in atom_types_in_target]))

    if target == 'system':
        output = output[0] * puw.unit(units)
    else:
        output = puw.quantity(np.array(output), units)

    return output
コード例 #16
0
ファイル: wrap_to_pbc.py プロジェクト: uibcdf/MolSysMT
def wrap_to_pbc(molecular_system,
                selection='all',
                structure_indices='all',
                center='[0,0,0] nanometers',
                center_of_selection=None,
                weights_for_center=None,
                recenter=True,
                keep_covalent_bonds=False,
                syntaxis='MolSysMT',
                engine='MolSysMT',
                in_place=False):

    engine = digest_engine(engine)
    structure_indices = digest_structure_indices(structure_indices)

    if engine == 'MolSysMT':

        from molsysmt.basic import select, get, set, extract, copy

        atom_indices = select(molecular_system,
                              selection=selection,
                              syntaxis=syntaxis)

        coordinates = get(molecular_system,
                          target='atom',
                          indices=atom_indices,
                          coordinates=True)
        length_units = puw.get_unit(coordinates)
        n_structures = coordinates.shape[0]
        n_atoms = coordinates.shape[1]
        box, box_shape = get(molecular_system,
                             target='system',
                             structure_indices=structure_indices,
                             box=True,
                             box_shape=True)
        box = puw.convert(box, to_unit=length_units)

        orthogonal = 0
        if box_shape is None:
            raise ValueError(
                "The system has no PBC box. The input argument 'pbc' can not be True."
            )
        elif box_shape == 'cubic':
            orthogonal = 1

        if center_of_selection is not None:

            from molsysmt.structure import get_center
            center = get_center(molecular_system,
                                selection=center_of_selection,
                                weights=weights_for_center,
                                structure_indices=structure_indices,
                                syntaxis=syntaxis,
                                engine='MolSysMT')

            center = puw.convert(center, to_unit=length_units)
            center = puw.get_value(center)

        else:

            center = puw.quantity(center)
            center = puw.convert(center, to_unit=length_units)
            center = puw.get_value(center)

            center_shape = np.shape(center)
            if len(center_shape) == 1 and center_shape[-1] == 3:
                center = np.tile(center, [n_structures, 1, 1])
            elif len(center_shape) == 2 and center_shape[
                    -1] == 3 and center_shape[0] == n_structures:
                center = np.expand_dims(center, axis=1)
            elif len(center_shape
                     ) == 2 and center_shape[-1] == 3 and center_shape[0] == 1:
                center = np.tile(center[0], [n_structures, 1, 1])
            elif len(center_shape
                     ) == 3 and center_shape[-1] == 3 and center_shape[
                         0] == n_structures and center_shape[1] == 1:
                center = np.array(center)
            else:
                raise ValueError('center needs the right shape')

        box = np.asfortranarray(puw.get_value(box), dtype='float64')
        coordinates = np.asfortranarray(puw.get_value(coordinates),
                                        dtype='float64')
        center = np.asfortranarray(center, dtype='float64')

        libbox.wrap_pbc(coordinates, center, box, orthogonal, n_atoms,
                        n_structures)

        if recenter:
            translation = np.tile(-center, (n_atoms, 1))
            coordinates += translation

        coordinates = np.ascontiguousarray(coordinates) * length_units

    else:

        raise NotImpementedEngineError()

    if in_place:

        set(molecular_system,
            target='atom',
            indices=atom_indices,
            structure_indices=structure_indices,
            syntaxis=syntaxis,
            coordinates=coordinates)

        pass

    else:

        tmp_molecular_system = copy(molecular_system)
        set(tmp_molecular_system,
            target='atom',
            indices=atom_indices,
            structure_indices=structure_indices,
            syntaxis=syntaxis,
            coordinates=coordinates)

        return tmp_molecular_system
コード例 #17
0
ファイル: charge.py プロジェクト: uibcdf/MolSysMT
def charge(molecular_system,
           target='group',
           selection='all',
           type=None,
           engine='OpenMM'):

    from molsysmt._private._digestion import digest_engine, digest_target

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

    if type in ['physical_pH7', 'collantes']:

        from molsysmt.basic import get

        from molsysmt.physico_chemical_properties.groups.charge import units
        if type == 'physical_pH7':
            from molsysmt.physico_chemical_properties.groups.charge import physical_pH7 as values, units
        elif type == 'collantes':
            from molsysmt.physico_chemical_properties.groups.charge import collantes as values, units
        else:
            raise NotImplementedError()

        output = []

        if target == 'atom':
            raise ValueError(
                'Only targets bigger than, or equal to, groups are allowed when type is "physical_pH7" or "collantes"'
            )

        elif target == 'group':

            group_names = get(molecular_system,
                              target=target,
                              selection=selection,
                              group_name=True)
            for ii in group_names:
                output.append(values[ii.upper()])

        elif target in ['component', 'molecule', 'chain', 'entity']:

            group_names = get(molecular_system,
                              target=target,
                              selection=selection,
                              group_name=True)
            for aux in group_names:
                output.append(np.sum([values[ii.upper()] for ii in aux]))

        elif target == 'system':

            group_names = get(molecular_system,
                              target='group',
                              selection='all',
                              group_names=True)
            output.append(np.sum([values[ii.upper()] for ii in group_names]))

        if target == 'system':
            output = output[0] * puw.unit(units)
        else:
            output = puw.quantity(np.array(output), units)

    else:

        from molsysmt._private._digestion import digest_molecular_system
        from molsysmt.basic import get, convert, get_form

        molecular_system = digest_molecular_system(molecular_system)

        if engine == 'OpenMM':

            from openmm import NonbondedForce

            openmm_system = convert(molecular_system, to_form='openmm.System')

            output = []

            if target == 'atom':

                atom_indices = get(molecular_system,
                                   target=target,
                                   selection=selection,
                                   atom_index=True)

                for force_index in range(openmm_system.getNumForces()):
                    force = openmm_system.getForce(force_index)
                    if isinstance(force, NonbondedForce):
                        for index in atom_indices:
                            output.append(
                                force.getParticleParameters(
                                    int(index))[0]._value)

                output = np.array(output, dtype=float).round(4) * puw.unit('e')

            elif target in [
                    'group', 'component', 'chain', 'molecule', 'entity'
            ]:

                atom_indices = get(molecular_system,
                                   target=target,
                                   selection=selection,
                                   atom_index=True)

                for force_index in range(openmm_system.getNumForces()):
                    force = openmm_system.getForce(force_index)
                    if isinstance(force, NonbondedForce):
                        for atom_list in atom_indices:
                            var_aux = 0.0
                            for index in atom_list:
                                var_aux += force.getParticleParameters(
                                    int(index))[0]._value
                            output.append(var_aux)

                output = np.array(output, dtype=float).round(4) * puw.unit('e')

            elif target == 'system':

                atom_indices = get(molecular_system,
                                   target='atom',
                                   selection='all',
                                   index=True)

                var_aux = 0.0
                for force_index in range(openmm_system.getNumForces()):
                    force = openmm_system.getForce(force_index)
                    if isinstance(force, NonbondedForce):
                        for index in atom_indices:
                            var_aux += force.getParticleParameters(
                                int(index))[0]._value

                output = np.round(var_aux, 4) * puw.unit('e')

        else:

            raise NotImplementedError

    return output