Exemplo n.º 1
0
 def __init__(self):
     super(MonoLJ, self).__init__()
     lj_proto = mb.Particle(name='LJ', pos=[0, 0, 0])
     
     pattern = mb.Grid3DPattern(5, 5, 5)
     pattern.scale(5)
     
     for pos in pattern:
         lj_particle = mb.clone(lj_proto)
         lj_particle.translate(pos)
         self.add(lj_particle)
Exemplo n.º 2
0
    def __init__(self, n, density):
        super(LJBox, self).__init__()

        box_length = (n / density)**(1 / 3)
        box = mb.Box(lengths=np.ones(3) * box_length)

        print(
            "Creating box ({:.4f} x {:.4f} x {:.4f}) containing {} particles at a "
            "number density of {}.".format(*box.lengths, n, density))

        particles_per_len = round(n**(1 / 3))
        pattern = mb.Grid3DPattern(particles_per_len, particles_per_len,
                                   particles_per_len)
        pattern.scale(box_length)
        for pos in pattern:
            self.add(mb.Particle(name='_LJ', pos=pos - box.lengths / 2))
        self.periodicity = box.lengths
Exemplo n.º 3
0
 def test_grid_3d(self):
     pattern = mb.Grid3DPattern(10, 5, 2)
     assert len(pattern) == 100
Exemplo n.º 4
0
def solvate_bilayer(system=None,
                    n_x=8,
                    n_y=8,
                    n_solvent_per_lipid=5,
                    water_spacing=0.3,
                    res_index=0,
                    lipid_atom_dict=None,
                    atom_index=0):
    """ Solvate the top and bottom parts of the bilayer, return water box

    Parameters
    ---------
    n_x : int
        3D grid dimension
    n_y : int
        3D grid dimension
    n_solvent_per_lipid : int
        Number of water beads per lipid, another grid dimension
    res_index : int
        Starting residue index for leaflet construction and residue counting
    lipid_atom_dict : OrderedDict()
        Dictionary whose values are mb.Compounds()s and values are a list of atom indices of that compound
    atom_index : int
        Counter for indexing atoms for lipid_atom_dict


    Returns
    -------
    solvated_system : mb.Compound()
        System with water solvating the outside of the bilayer
    water_box : mb.Box()
        Box object that accounts fot water molecules
    lipid_atom_dict : OrderedDict()
        Dictionary whose values are mb.Compounds()s and values are a list of atom indices of that compound
    atom_index : int
        Counter for indexing atoms for lipid_atom_dict

    """
    # Construct 3D grid of water
    # Compute distances to translate such that water is either below or above bilayer
    # Add to table of contents file for post processing
    length = max(system.xyz[:, 0])
    width = max(system.xyz[:, 1])
    n_solvent_leaflet = n_x * n_y * n_solvent_per_lipid
    n_water_x = int(np.floor(length / water_spacing))
    n_water_y = int(np.floor(width / water_spacing))
    n_water_z = int(np.ceil(n_solvent_leaflet / (n_water_x * n_water_y)))
    height = n_water_z * water_spacing
    residues.add(HOH().name)
    #cube = mb.Grid3DPattern(n_x, n_y, n_solvent_per_lipid)
    #cube.scale( [ water_spacing * n_x, water_spacing * n_y, water_spacing * n_solvent_per_lipid])
    cube = mb.Grid3DPattern(n_water_x, n_water_y, n_water_z)
    cube.scale([length, width, height])
    bot_water_list = cube.apply(HOH())
    bot_water_list = bot_water_list[:n_solvent_leaflet]
    bot_water = mb.Compound()
    for compound in bot_water_list:
        bot_water.add(compound)
    highest_botwater = max(bot_water.xyz[:, 2])
    lowest_botlipid = min(system.xyz[:, 2])
    #shift_botwater = abs(highest_botwater - lowest_botlipid) + 0.3
    shift_botwater = abs(highest_botwater - lowest_botlipid) + 0.1
    bot_water.translate([0, 0, -1 * shift_botwater])

    # Construct 3D grid of water
    # Compute distances to translate such that water is either below or above bilayer
    # Add to table of contents file for post processing
    # cube = mb.Grid3DPattern(n_x, n_y, n_solvent_per_lipid)
    # cube.scale( [ water_spacing * n_x, water_spacing * n_y, water_spacing * n_solvent_per_lipid])
    cube = mb.Grid3DPattern(n_water_x, n_water_y, n_water_z)
    cube.scale([length, width, height])
    top_water_list = cube.apply(HOH())
    top_water_list = top_water_list[:n_solvent_leaflet]
    top_water = mb.Compound()
    for compound in top_water_list:
        top_water.add(compound)
    lowest_topwater = min(top_water.xyz[:, 2])
    highest_toplipid = max(system.xyz[:, 2])
    #shift_topwater = abs(highest_toplipid - lowest_topwater) + 0.3
    shift_topwater = abs(highest_toplipid - lowest_topwater) + 0.1
    top_water.translate([0, 0, shift_topwater])
    # Add waters to table of contents

    system.add(bot_water)
    system.add(top_water)

    #waterbox = mb.Box(mins = [0,0,0], maxs = [max(top_water.xyz[:,0])+0.2, max(top_water.xyz[:,1])+0.2, max(top_water.xyz[:,2])+0.2])
    #waterbox = mb.Box(mins = [0,0,0], maxs = [max(system.xyz[:,0])+0.2, max(system.xyz[:,1])+0.2, max(system.xyz[:,2])+0.2])

    # Add waters to lipid_atom_dict
    lipid_atom_dict['SOL'] = list(
        range(
            atom_index, atom_index +
            (2 * n_x * n_y * n_solvent_per_lipid * HOH().n_particles), 1))
    atom_index += 2 * n_x * n_y * n_solvent_per_lipid * HOH().n_particles
    return system, lipid_atom_dict, atom_index
Exemplo n.º 5
0
        # we need to scale the coordinates appropriately, since they are taken only
        # from the final frame.
        scaling_ratio = [
            new / old
            for old, new in zip(original_box.lengths, avg_box_lengths)
        ]
        print("scaling_ratio: {}".format(scaling_ratio))
        for particle in mb_compound.particles():
            for i, frame in enumerate(particle.xyz):
                particle.xyz[i] = [
                    factor * coord
                    for factor, coord in zip(scaling_ratio, particle.xyz[i])
                ]

        # Tile this using grid 3d pattern
        cube = mb.Grid3DPattern(2, 2, 2)
        # Define a new box based on average box lengths from AA traj, scaled by 8
        new_box = mb.Box(lengths=[2 * length for length in avg_box_lengths])
        # Scale pattern lengths based on the new box lengths
        cube.scale([length for length in new_box.lengths])
        replicated = cube.apply(mb_compound)
        mirrored_image = mb.Compound()
        for item in replicated:
            mirrored_image.add(item)

        # Particle renaming due to mbuild coarsegrained format
        for particle in mb_compound.particles():
            particle.name = "_" + particle.name.strip()
        for particle in mirrored_image.particles():
            particle.name = "_" + particle.name.strip()
Exemplo n.º 6
0
import mbuild as mb
import foyer
import numpy
import mdtraj
import pdb

single_propane = mb.load('propane_ua.mol2')
single_propane.name = "prop"
#system = mb.fill_box(single_propane, n_compounds = 100, density = 1.0)
cube = mb.Grid3DPattern(10, 10, 10)
cube.scale([5, 5, 5])
cube_list = cube.apply(single_propane)
system = mb.Compound()
for compound in cube_list:
    system.add(compound)

system.save('propane.gro', overwrite=True, residues=['prop'])
#system.save('propane.top', forcefield_files='small_ff.xml', overwrite=True)