Beispiel #1
0
    def __init__(self, ball_radius=10, n_chains=4, chain_length=10, monomer=None):
        """Initialize a tethered nanoparticle.

        Args:
            ball_radius (float): Radius of the nanoparticle.
            n_chains (int): Number of chains to attach to the nanoparticle.
            chain_length (int): Length of the chains being attached.
            monomer (Compound, optional): Type of chain being attached.
        """
        super(Tnp, self).__init__()

        if not monomer:
            monomer = Bead(particle_kind='t')

        n = 129  # TODO: make this tweakable
        self.add(Sphere(n=n, radius=ball_radius, port_distance_from_surface=0.7), label="np")

        # Generate 65 points on the surface of a unit sphere.
        pattern = mb.SpherePattern(n_chains)

        # Magnify it a bit.
        pattern.scale(ball_radius)

        chain_proto = mb.Polymer(monomer, n=chain_length)

        # Apply chains to pattern.
        chain_protos, empty_backfill = pattern.apply_to_compound(chain_proto,
                guest_port_name="down", host=self['np'])
        self.add(chain_protos)

        self.generate_bonds('np', 'np', sqrt(4 * ball_radius ** 2 * pi / n) - 0.5,
                            sqrt(4 * ball_radius**2 * pi / n) + 0.5)
        self.generate_bonds('np', 't', 0.1, 0.3)
        self.generate_bonds('t', 'np', 0.1, 0.3)
Beispiel #2
0
 def IsotropicPattern(self):
     radius = 2.5
     point_density = 3.0
     pattern = mb.SpherePattern(
         int(point_density * 4.0 * np.pi * radius**2.0))
     pattern.scale(radius)
     return pattern
Beispiel #3
0
            def __init__ (self, radius, bead_diameter):
                super(Core, self).__init__()
                
                core_bead = mb.Particle(name='_CGN')

                # calculate n number of core particles from ratio of core total SA and single bead SA
                n_core_particles = (int)((4*np.pi*(radius**2))/(4*np.pi*(bead_diameter/2)**2))
                
                # arrange beads into a sphere pattern and add it to the compound
                core_pattern = mb.SpherePattern(n_core_particles)
                core_pattern.scale(radius)

                core_formation = core_pattern.apply(core_bead)
                self.add(core_formation)
                
                self.generate_bonds(name_a='_CGN', name_b='_CGN', dmin=bead_diameter*2-0.4, dmax=bead_diameter*2+0.3)

                print('Core beads added.')

                # apply ports to each bead in core_formation
                for i, pos in enumerate(core_pattern.points):
                    port = mb.Port(anchor=core_formation[i], orientation=pos, separation=radius/5)
                    self.add(port, label='port[$]')

                print('Ports added to core')
Beispiel #4
0
def _restore_atoms(coarse_grained, aa_system, aa_hierarchy):
    """ Optimize aa coordinates

    Parameters
    ----------
    coarse_grained : mb.Compound
        CG structure
    aa_system : mb.Compound
        AA structure with unoptimized coordinates
    aa_hierarchy : OrderedDict()
        {mb.Compound molecule : {mb.Compound bead : [mb.Compound atom ]}}


    Returns
    -------
    aa_system : mb.Compound
        AA structure with optimized coordinates

    Notes
    -----
    Generates a sphere of points around each bead

        """
    for molecule in aa_hierarchy.keys():
        for bead in aa_hierarchy[molecule]:
            spherical_pattern = mb.SpherePattern(
                n=len(aa_hierarchy[molecule][bead]) + 1, scale=0.1)
            sphere = spherical_pattern.apply(bead)
            for index, atom in enumerate(aa_hierarchy[molecule][bead]):
                atom.translate(sphere[index].pos)

    return aa_system
Beispiel #5
0
    def __init__(self, n=65, radius=1, port_distance_from_surface=.07):
        """Initialize a Sphere object.

        Args:
            n (int): Number of points used to construct the Sphere.
            radius (float): Radius of the Sphere.
            port_distance_from_surface (float): Distance of Ports from Sphere.
        """
        super(Sphere, self).__init__()

        # Generate 65 points on the surface of a unit sphere.
        pattern = mb.SpherePattern(n)
        # Magnify the unit sphere by the provided radius.
        pattern.scale(radius)

        # Create particles and Ports at pattern positions.
        for i, pos in enumerate(pattern.points):
            particle = mb.Particle(name="np", pos=pos)
            self.add(particle, "np_{}".format(i))
            port = mb.Port(anchor=particle)
            self.add(port, "port_{}".format(i))

            # Make the top of the port point toward the positive x axis.
            port.spin(-pi / 2, [0, 0, 1])
            # Raise up (or down) the top of the port in the z direction.
            port.spin(-arcsin(pos[2] / radius), [0, 1, 0])
            # Rotate the Port along the z axis.
            port.spin(arctan2(pos[1], pos[0]), [0, 0, 1])
            # Move the Port a bit away from the surface of the Sphere.
            port.translate(pos / radius * port_distance_from_surface)
Beispiel #6
0
    def __init__(self, chain_density, radius, seed=12345, **args):
        np.random.seed(12345)
        pattern = mb.SpherePattern(
            int(chain_density * 20.0 * np.pi * radius**2.0))
        pattern.scale(radius)
        np.random.shuffle(pattern.points)
        points = pattern.points[:int(len(pattern.points) / 5)]

        super(RandomPattern, self).__init__(points=points, orientations=None)
Beispiel #7
0
 def __init__(self, chain_density, radius, fractional_sa, **args):
     pattern = mb.SpherePattern(int(chain_density * 4.0 * np.pi * radius**2.0))
     pattern.scale(radius)
     total_sa = 4.0 * np.pi * radius**2.0
     patch_sa = total_sa * fractional_sa
     width = patch_sa / (2 * np.pi * radius)
     points = np.array([xyz for xyz in pattern.points if xyz[2] < (-width)/2
                       or xyz[2] > width/2])
     super(EquatorialPattern, self).__init__(points=points, orientations=None)
Beispiel #8
0
 def __init__(self, chain_density, radius, fractional_sa, **args):
     pattern = mb.SpherePattern(
         int(chain_density * 4.0 * np.pi * radius**2.0))
     pattern.scale(radius)
     total_sa = 4.0 * np.pi * radius**2.0
     patch_sa = total_sa * fractional_sa
     cutoff = patch_sa / (2 * np.pi * radius)
     points = np.array(
         [xyz for xyz in pattern.points if xyz[2] < radius - cutoff])
     super(PolarPattern, self).__init__(points=points, orientations=None)
Beispiel #9
0
    def __init__(self,
                 radius=4,
                 chain_prototype='pegsilane',
                 chain_density=0.5,
                 chain_length=17):
        super(SilicaTNP, self).__init__()

        surface_area = 4.0 * np.pi * radius**2.0
        n_chains = int(chain_density * surface_area)
        pattern = mb.SpherePattern(n_chains)
        silica_radius = 0.201615

        core_particles = ['Si', 'O']
        shell = SilicaSphere(n=n_chains, radius=radius)
        shell.translate_to((0, 0, 0))
        core = SilicaNP(radius=radius)
        core.translate_to((0, 0, 0))
        self.add(shell, 'shell')
        self.add(core, 'core')

        if chain_prototype == 'alkane':
            chain_prototype = Alkane(n=chain_length, cap_end=False)
        elif chain_prototype == 'alkylsilane':
            chain_prototype = Alkylsilane(n=chain_length)
        elif chain_prototype == 'peg':
            chain_prototype = PEG(n=chain_length, cap_end=False)
        elif chain_prototype == 'pegsilane':
            chain_prototype = PEGSilane(n=chain_length)
        else:
            raise MbuildError('chain prototype not supported')

        # This radius is for an alkane chain,
        # PEG probably close enough to this
        chain_bead_radius = 0.4582 / 2
        port_separation = np.linalg.norm(chain_prototype['down'].pos - \
                                chain_prototype['down'].anchor.pos)
        pattern.scale(radius + silica_radius + chain_bead_radius - \
                      port_separation)

        chains, _ = pattern.apply_to_compound(guest=chain_prototype,
                                              guest_port_name='down',
                                              host=self['shell'])
        self.add(chains)
        """
Beispiel #10
0
    def __init__(self, n=65, radius=1, port_distance_from_surface=.07):
        """Initialize a Sphere object.

        Args:
            n (int): Number of points used to construct the Sphere.
            radius (float): Radius of the Sphere.
            port_distance_from_surface (float): Distance of Ports from Sphere.
        """
        super(SilicaSphere, self).__init__()
        particle = mb.load('O=[Si]=O', smiles=True)
        particle.name = 'Silica'
        particle.add(mb.Port(anchor=particle[1]), label='out')

        # Generate 65 points on the surface of a unit sphere.
        pattern = mb.SpherePattern(n)
        # Magnify the unit sphere by the provided radius.
        pattern.scale(radius)

        particles = pattern.apply(particle, orientation='normal', compound_port='out')
        self.add(particles, label='silica_[$]')

        # Create particles and Ports at pattern positions.
        for i, pos in enumerate(pattern.points):
            particle = mb.load('O=[Si]=O', smiles=True)

            particle.translate_to(pos)
            self.add(particle, "silica_{}".format(i))
            port = mb.Port(anchor=particle)
            self.add(port, "port_{}".format(i))

            # Make the top of the port point toward the positive x axis.
            port.spin(-pi/2, [0, 0, 1]) 
            # Raise up (or down) the top of the port in the z direction.
            port.spin(-arcsin(pos[2]/radius), [0, 1, 0]) 
            # Rotate the Port along the z axis.
            port.spin(arctan2(pos[1], pos[0]), [0, 0, 1]) 
            # Move the Port a bit away from the surface of the Sphere.
            port.translate(pos/radius * port_distance_from_surface)

        for bond in self.bonds():
            self.remove_bond(bond)
Beispiel #11
0
def count_patch_points(pattern, radius, chain_density):
    ''' Counts and returns the amount of points that are being removed in a certain nanoparticle coating pattern.

    Parameters
    ----------
    pattern : mb.Pattern
        Nanoparticle coating pattern to count which points were removed
    radius : float
        Radius of the nanoparticle
    chain_density : float
        Density of chains on the nanoparticle surface
    '''
    isotropic_pattern = mb.SpherePattern(int(chain_density*4.0*np.pi*radius**2))
    isotropic_pattern.scale(radius)
     
    patch = []
    for point in isotropic_pattern.points:
        if not np.all(np.isin(point, pattern.points)):
            patch.append(point)

    return len(patch)
Beispiel #12
0
 def test_sphere(self):
     pattern = mb.SpherePattern(100)
     assert len(pattern) == 100
    def __init__(self,
                 radius,
                 chain_density,
                 chain_length,
                 core_fidelity='AA',
                 chain_fidelity='UA',
                 bead_diameter=None,
                 bvf=None):
        super(TNP, self).__init__()

        if core_fidelity == 'AA':
            core_particles = ['Si', 'O']
            core = AA_nano(radius=radius)
        elif core_fidelity == 'CG':
            if not bead_diameter:
                raise Exception("`bead_diameter` must be defined when "
                                "`core_fidelity`='CG'")
            if not bvf:
                raise Exception("`bvf` must be defined when "
                                "`core_fidelity`='CG'")
            core_particles = ['_CGN']
            core = CG_nano(radius=radius, bead_diameter=bead_diameter, bvf=bvf)
        else:
            raise Exception("`core_fidelity` must be either 'AA' or 'CG'.")

        self.add(core, 'core')

        chain_prototype = Alkane(chain_length=chain_length,
                                 fidelity=chain_fidelity,
                                 cap_front=False)

        surface_area = 4.0 * np.pi * radius**2.0
        n_chains = int(chain_density * surface_area)
        pattern = mb.SpherePattern(n_chains)
        silica_radius = 0.201615
        if chain_fidelity == 'UA':
            chain_bead_radius = 0.395 / 2
        else:
            chain_bead_radius = 0.4582 / 2
        port_separation = np.linalg.norm(chain_prototype['up'].pos - \
                                chain_prototype['up'].anchor.pos)
        pattern.scale(radius + silica_radius + chain_bead_radius - \
                      port_separation)
        '''
        Chains are placed such that the end bead closest to the
        nanoparticle core is located at R + sigma from the nanoparticle
        center, where R is the nanoparticle radius and sigma is the
        arithmetic average of the CG pseudo-atom diameter and the chain
        end bead diameter.
        '''

        for position in pattern.points:
            port = mb.Port(anchor=self['core'], orientation=position,
                    separation=radius + silica_radius + \
                               chain_bead_radius - port_separation)
            self['core'].add(port, "attachment_site[$]")

        chains, _ = pattern.apply_to_compound(chain_prototype,
                                              guest_port_name='up',
                                              host=self['core'])
        self.add(chains)

        self.label_rigid_bodies(rigid_particles=core_particles)
        for bond in self.bonds():
            if (bond[0].name in ['AA_nano', 'CG_nano']
                    or bond[1].name in ['AA_nano', 'CG_nano']):
                if 'nano' in bond[0].name:
                    bond[1].rigid_id = 0
                if 'nano' in bond[1].name:
                    bond[0].rigid_id = 0
                self.remove_bond(bond)
Beispiel #14
0
    def __init__(self, chain_density, radius, fractional_sa, **args):

        pattern = mb.SpherePattern(
            int(chain_density * 4.0 * np.pi * radius**2.0))
        pattern.scale(radius)
        total_sa = 4.0 * np.pi * radius**2.0
        patch_sa = total_sa * fractional_sa
        patch_cutoff = np.sqrt((patch_sa) / (4 * np.pi))
        #cutoff = patch_sa / (8 * np.pi * radius)
        cutoff = patch_cutoff

        #spherical_points = cartesian_to_spherical(pos=pattern.points)

        bottom_patch1 = np.array((radius, 0, (0 + (109.5 * np.pi / 180))))
        bottom_patch2 = np.array(
            (radius, (120 * np.pi / 180), bottom_patch1[2]))
        bottom_patch3 = np.array(
            (radius, bottom_patch2[1] + (120 * np.pi / 180), bottom_patch1[2]))

        bottom_patch1_cartesian = spherical_to_cartesian(pos=bottom_patch1)
        bottom_patch2_cartesian = spherical_to_cartesian(pos=bottom_patch2)
        bottom_patch3_cartesian = spherical_to_cartesian(pos=bottom_patch3)

        points = []
        '''
        for xyz in pattern.points:
            if xyz[0] > top_patch_cartesian[0]-patch_cutoff and xyz[0] < top_patch_cartesian[0]+patch_cutoff and xyz[1] > top_patch_cartesian[1]-patch_cutoff and xyz[1] < top_patch_cartesian[1]+patch_cutoff and xyz[2] > top_patch_cartesian[2]-patch_cutoff and xyz[2] < top_patch_cartesian[2]+patch_cutoff:
                points.append(xyz)
        '''
        for xyz in pattern.points:
            if xyz[0] > bottom_patch1_cartesian[0] - patch_cutoff and xyz[
                    0] < bottom_patch1_cartesian[0] + patch_cutoff and xyz[
                        1] > bottom_patch1_cartesian[1] - patch_cutoff and xyz[
                            1] < bottom_patch1_cartesian[
                                1] + patch_cutoff and xyz[
                                    2] > bottom_patch1_cartesian[
                                        2] - patch_cutoff and xyz[
                                            2] < bottom_patch1_cartesian[
                                                2] + patch_cutoff:
                points.append(xyz)

        for xyz in pattern.points:
            if xyz[0] > bottom_patch2_cartesian[0] - patch_cutoff and xyz[
                    0] < bottom_patch2_cartesian[0] + patch_cutoff and xyz[
                        1] > bottom_patch2_cartesian[1] - patch_cutoff and xyz[
                            1] < bottom_patch2_cartesian[
                                1] + patch_cutoff and xyz[
                                    2] > bottom_patch2_cartesian[
                                        2] - patch_cutoff and xyz[
                                            2] < bottom_patch2_cartesian[
                                                2] + patch_cutoff:
                points.append(xyz)

        for xyz in pattern.points:
            if xyz[0] > bottom_patch3_cartesian[0] - patch_cutoff and xyz[
                    0] < bottom_patch3_cartesian[0] + patch_cutoff and xyz[
                        1] > bottom_patch3_cartesian[1] - patch_cutoff and xyz[
                            1] < bottom_patch3_cartesian[
                                1] + patch_cutoff and xyz[
                                    2] > bottom_patch3_cartesian[
                                        2] - patch_cutoff and xyz[
                                            2] < bottom_patch3_cartesian[
                                                2] + patch_cutoff:
                points.append(xyz)

        reverse_pattern = []
        for point in pattern:
            if not np.all(np.isin(point, points)):
                reverse_pattern.append(point)

        super(RingPattern, self).__init__(points=reverse_pattern,
                                          orientations=None)
Beispiel #15
0
    def __init__(self,
                 radius,
                 chain_density,
                 bead_diameter=0.6,
                 backfill=None,
                 coating_pattern='isotropic',
                 fractional_sa=0.2,
                 **kwargs):
        super(cgnp_patchy, self).__init__()

        self.bead_diameter = bead_diameter

        nano = Nanoparticle(radius, bead_diameter)
        self.add(nano, 'nanoparticle')

        chain = CGAlkane()

        isotropic_pattern = mb.SpherePattern(
            int(chain_density * 4.0 * np.pi * radius**2.0))
        isotropic_pattern.scale(radius)

        if coating_pattern == 'isotropic':
            pattern = isotropic_pattern
        elif coating_pattern == 'polar':
            pattern = PolarPattern(chain_density, radius, fractional_sa,
                                   **kwargs)
        elif coating_pattern == 'bipolar':
            pattern = BipolarPattern(chain_density, radius, fractional_sa,
                                     **kwargs)
        elif coating_pattern == 'equatorial':
            pattern = EquatorialPattern(chain_density, radius, fractional_sa,
                                        **kwargs)
        elif coating_pattern == 'square':
            pattern = SquarePattern(chain_density, radius, fractional_sa,
                                    **kwargs)
        elif coating_pattern == 'random':
            pattern = RandomPattern(chain_density, radius, **kwargs)
        elif coating_pattern == 'cube':
            pattern = CubePattern(chain_density, radius, fractional_sa,
                                  **kwargs)
        elif coating_pattern == 'tetrahedral':
            pattern = TetrahedralPattern(chain_density, radius, fractional_sa,
                                         **kwargs)
        elif coating_pattern == 'ring':
            pattern = RingPattern(chain_density, radius, fractional_sa,
                                  **kwargs)
        else:
            raise Exception(
                "Coating pattern '{}' not supported. Valid options are 'polar', 'bipolar', 'isotropic', 'equatorial', 'square', 'random', 'cube', 'tetrahedral', and 'ring'."
                .format(coating_pattern))

        if backfill and coating_pattern == 'random':
            raise Exception(
                "Backfill not supported for coating pattern type 'random'.")
        elif backfill and coating_pattern == 'isotropic':
            raise Exception(
                "Backfill not supported for coating pattern type 'isotropic'.")

        if backfill:
            backfill_points = []
            for point in isotropic_pattern.points:
                if not np.all(np.isin(point, pattern.points)):
                    backfill_points.append(point)

        # Hacky workaround until apply_to_compound below can be used
        for pos in pattern.points:
            port = mb.Port(anchor=self['nanoparticle'],
                           orientation=pos,
                           separation=radius)
            self['nanoparticle'].add(port, 'port[$]')
            chain = CGAlkane()
            self.add(chain)
            mb.force_overlap(chain, chain['up'], port)

        #chain_protos, empty_backfill = pattern.apply_to_compound(guest=chain, guest_port_name='up', host=self)
        #self.add(chain_protos)

        if backfill:
            pattern.points = np.array(backfill_points)
            # Problems with apply_to_compound again, temporarily replaced with workaround used with pattern
            for pos in pattern.points:
                port = mb.Port(anchor=self['nanoparticle'],
                               orientation=pos,
                               separation=radius)
                self['nanoparticle'].add(port, 'b_port[$]')
                b_chain = mb.clone(backfill)
                self.add(b_chain)
                mb.force_overlap(b_chain, b_chain['up'], port)
            #backfill_protos, empty_backfill = pattern.apply_to_compound(backfill, guest_port_name='up', host=self['nanoparticle'])
            #self.add(backfill_protos)

        self.label_rigid_bodies(rigid_particles='_CGN')

        # This is a temporary workaround until the 'apply_to_compound' method in mBuild is fixed -Andrew
        # Has the problem this was working around been fixed yet? If so, this code can be updated.
        for bond in self.bonds():
            if bond[0].name == 'Nanoparticle' or bond[1].name == 'Nanoparticle':
                if bond[0].name == 'Nanoparticle':
                    bond[1].rigid_id = 0
                if bond[1].name == 'Nanoparticle':
                    bond[0].rigid_id = 0
                self.remove_bond(bond)
Beispiel #16
0
    def __init__(self, chain_density, radius, fractional_sa, **args):

        pattern = mb.SpherePattern(
            int(chain_density * 4.0 * np.pi * radius**2.0))
        pattern.scale(radius)
        total_sa = 4.0 * np.pi * radius**2.0
        patch_sa = total_sa * fractional_sa
        patch_cutoff = np.sqrt((patch_sa) / (4 * np.pi))
        #cutoff = patch_sa / (8 * np.pi * radius)
        cutoff = patch_cutoff

        #spherical_points = cartesian_to_spherical(pos=pattern.points)

        top_patch = np.array((radius, 0, 0))
        bottom_patch1 = np.array(
            (radius, 0, (top_patch[2] + (109.5 * np.pi / 180))))
        bottom_patch2 = np.array(
            (radius, (120 * np.pi / 180), bottom_patch1[2]))
        bottom_patch3 = np.array(
            (radius, bottom_patch2[1] + (120 * np.pi / 180), bottom_patch1[2]))

        top_patch_cartesian = spherical_to_cartesian(pos=top_patch)
        bottom_patch1_cartesian = spherical_to_cartesian(pos=bottom_patch1)
        bottom_patch2_cartesian = spherical_to_cartesian(pos=bottom_patch2)
        bottom_patch3_cartesian = spherical_to_cartesian(pos=bottom_patch3)

        points = []

        for xyz in pattern.points:
            if xyz[0] > top_patch_cartesian[0] - patch_cutoff and xyz[
                    0] < top_patch_cartesian[0] + patch_cutoff and xyz[
                        1] > top_patch_cartesian[1] - patch_cutoff and xyz[
                            1] < top_patch_cartesian[1] + patch_cutoff and xyz[
                                2] > top_patch_cartesian[
                                    2] - patch_cutoff and xyz[
                                        2] < top_patch_cartesian[
                                            2] + patch_cutoff:
                points.append(xyz)

        for xyz in pattern.points:
            if xyz[0] > bottom_patch1_cartesian[0] - patch_cutoff and xyz[
                    0] < bottom_patch1_cartesian[0] + patch_cutoff and xyz[
                        1] > bottom_patch1_cartesian[1] - patch_cutoff and xyz[
                            1] < bottom_patch1_cartesian[
                                1] + patch_cutoff and xyz[
                                    2] > bottom_patch1_cartesian[
                                        2] - patch_cutoff and xyz[
                                            2] < bottom_patch1_cartesian[
                                                2] + patch_cutoff:
                points.append(xyz)

        for xyz in pattern.points:
            if xyz[0] > bottom_patch2_cartesian[0] - patch_cutoff and xyz[
                    0] < bottom_patch2_cartesian[0] + patch_cutoff and xyz[
                        1] > bottom_patch2_cartesian[1] - patch_cutoff and xyz[
                            1] < bottom_patch2_cartesian[
                                1] + patch_cutoff and xyz[
                                    2] > bottom_patch2_cartesian[
                                        2] - patch_cutoff and xyz[
                                            2] < bottom_patch2_cartesian[
                                                2] + patch_cutoff:
                points.append(xyz)

        for xyz in pattern.points:
            if xyz[0] > bottom_patch3_cartesian[0] - patch_cutoff and xyz[
                    0] < bottom_patch3_cartesian[0] + patch_cutoff and xyz[
                        1] > bottom_patch3_cartesian[1] - patch_cutoff and xyz[
                            1] < bottom_patch3_cartesian[
                                1] + patch_cutoff and xyz[
                                    2] > bottom_patch3_cartesian[
                                        2] - patch_cutoff and xyz[
                                            2] < bottom_patch3_cartesian[
                                                2] + patch_cutoff:
                points.append(xyz)
        '''for xyz in pattern.points:
            if xyz[0] < (cutoff-radius)-top_patch_cartesian[0] and xyz[1] < (cutoff-radius)-top_patch_cartesian[1] and xyz[2] < (cutoff-radius)-top_patch_cartesian[2]:
                points.append(xyz)
            else:
                continue


        for xyz in pattern.points:
            if xyz[0] > (cutoff-radius)-top_patch_cartesian[0]: # or xyz[0] > cutoff-top_patch_cartesian[0]:
                if xyz[1] > (cutoff-radius)-top_patch_cartesian[1]: # or xyz[1] > cutoff-top_patch_cartesian[1]:
                    if xyz[2] > (cutoff-radius)-top_patch_cartesian[2]: # or xyz[2] > cutoff-top_patch_cartesian[2]:
                        points.append(xyz)
                    else:
                        continue
                else:
                    continue
            else:
                continue


        for xyz in pattern.points:
            if xyz[0] < (cutoff)-bottom_patch1_cartesian[0] and xyz[1] < (cutoff)-bottom_patch1_cartesian[1] and xyz[2] < (cutoff)-bottom_patch1_cartesian[2]:
                points.append(xyz)
            else:
                continue
        
        for xyz in pattern.points:
            if xyz[0] < (cutoff-radius)-bottom_patch1_cartesian[0]:# or xyz[0] > cutoff-bottom_patch1_cartesian[0]:
                if xyz[1] < (cutoff-radius)-bottom_patch1_cartesian[1]: # or xyz[1] > cutoff-bottom_patch1_cartesian[1]:
                    if xyz[2] < (cutoff-radius)-bottom_patch1_cartesian[2]: # or xyz[2] > cutoff-bottom_patch1_cartesian[2]:
                        points.append(xyz)
                    else:
                        continue
                else:
                    continue
            else:
                continue

        for xyz in pattern.points:
            if xyz[0] > (cutoff-radius)-bottom_patch1_cartesian[0]:# or xyz[0] > cutoff-bottom_patch1_cartesian[0]:
                if xyz[1] > (cutoff-radius)-bottom_patch1_cartesian[1]: # or xyz[1] > cutoff-bottom_patch1_cartesian[1]:
                    if xyz[2] > (cutoff-radius)-bottom_patch1_cartesian[2]: # or xyz[2] > cutoff-bottom_patch1_cartesian[2]:
                        points.append(xyz)
                    else:
                        continue
                else:
                    continue
            else:
                continue

        for xyz in pattern.points:
            if xyz[0] < (cutoff)-bottom_patch2_cartesian[0] and xyz[1] < (cutoff)-bottom_patch2_cartesian[1] and xyz[2] < (cutoff)-bottom_patch2_cartesian[2]:
                points.append(xyz)
            else:
                continue

        for xyz in pattern.points:
            if xyz[0] < (cutoff-radius)-bottom_patch2_cartesian[0]: # or xyz[0] > cutoff-bottom_patch2_cartesian[0]:
                if xyz[1] < (cutoff-radius)-bottom_patch2_cartesian[1]: # or xyz[1] > cutoff-bottom_patch2_cartesian[1]:
                    if xyz[2] < (cutoff-radius)-bottom_patch2_cartesian[2]: # or xyz[2] > cutoff-bottom_patch2_cartesian[2]:
                        points.append(xyz)
                    else:
                        continue
                else:
                    continue
            else:
                continue

        for xyz in pattern.points:
            if xyz[0] > (cutoff-radius)-bottom_patch2_cartesian[0]:# or xyz[0] > cutoff-bottom_patch1_cartesian[0]:
                if xyz[1] > (cutoff-radius)-bottom_patch2_cartesian[1]: # or xyz[1] > cutoff-bottom_patch1_cartesian[1]:
                    if xyz[2] > (cutoff-radius)-bottom_patch2_cartesian[2]: # or xyz[2] > cutoff-bottom_patch1_cartesian[2]:
                        points.append(xyz)
                    else:
                        continue
                else:
                    continue
            else:
                continue

        for xyz in pattern.points:
            if xyz[0] > (cutoff-radius)-bottom_patch3_cartesian[0]: # or xyz[0] > cutoff-bottom_patch3_cartesian[0]:
                if xyz[1] > (cutoff-radius)-bottom_patch3_cartesian[1]: # or xyz[1] > cutoff-bottom_patch3_cartesian[1]:
                    if xyz[2] > (cutoff-radius)-bottom_patch3_cartesian[2]: # or xyz[2] > cutoff-bottom_patch3_cartesian[2]:
                        points.append(xyz)
                    else:
                        continue
                else:
                    continue
            else:
                continue

        for xyz in pattern.points:
            if xyz[0] < (cutoff-radius)-bottom_patch3_cartesian[0]: # or xyz[0] > cutoff-bottom_patch3_cartesian[0]:
                if xyz[1] < (cutoff-radius)-bottom_patch3_cartesian[1]: # or xyz[1] > cutoff-bottom_patch3_cartesian[1]:
                    if xyz[2] < (cutoff-radius)-bottom_patch3_cartesian[2]: # or xyz[2] > cutoff-bottom_patch3_cartesian[2]:
                        points.append(xyz)
                    else:
                        continue
                else:
                    continue
            else:
                continue
        
        for xyz in pattern.points:
            if xyz[0] < (cutoff)-bottom_patch3_cartesian[0] and xyz[1] < (cutoff)-bottom_patch3_cartesian[1] and xyz[2] < (cutoff)-bottom_patch3_cartesian[2]:
                points.append(xyz)
            else:
                continue'''

        # This pattern was written backwards, meaning that it returned the patches instead of everything but the patches. The code below is a temporary way to fix this until the math can be altered.
        reverse_pattern = []
        for point in pattern:
            if not np.all(np.isin(point, points)):
                reverse_pattern.append(point)

        super(TetrahedralPattern, self).__init__(points=reverse_pattern,
                                                 orientations=None)
Beispiel #17
0
 def test_sphere_float(self):
     pattern = mb.SpherePattern(n=100.2)
     assert len(pattern) == 100
     assert not np.any(np.isnan(pattern.points))