def __init__(self, anchor=None, orientation=None, separation=0): super(Port, self).__init__(name='Port', port_particle=True) self.anchor = anchor up = Compound(name='subport', port_particle=True) up.add( Particle(name='G', pos=[0.005, 0.0025, -0.0025], port_particle=True), 'middle') up.add( Particle(name='G', pos=[0.005, 0.0225, -0.0025], port_particle=True), 'top') up.add( Particle(name='G', pos=[-0.015, -0.0075, -0.0025], port_particle=True), 'left') up.add( Particle(name='G', pos=[0.005, -0.0175, 0.0075], port_particle=True), 'right') down = clone(up) down.rotate(np.pi, [0, 0, 1]) self.add(up, 'up') self.add(down, 'down') self.used = False if orientation is None: orientation = [0, 1, 0] default_direction = [0, 1, 0] if np.array_equal(np.asarray(default_direction), unit_vector(-np.asarray(orientation))): self.rotate(np.pi, [1, 0, 0]) elif np.array_equal(np.asarray(default_direction), unit_vector(np.asarray(orientation))): pass else: normal = np.cross(default_direction, orientation) self.rotate(angle(default_direction, orientation), normal) if anchor: self.translate_to(anchor.pos) self.translate(separation * unit_vector(orientation))
def __init__(self, anchor=None, orientation=None, separation=0): super(Port, self).__init__(name='Port', port_particle=True) self.anchor = anchor up = Compound(name='subport', port_particle=True) up.add(Particle(name='G', pos=[0.005, 0.0025, -0.0025], port_particle=True), 'middle') up.add(Particle(name='G', pos=[0.005, 0.0225, -0.0025], port_particle=True), 'top') up.add(Particle(name='G', pos=[-0.015, -0.0075, -0.0025], port_particle=True), 'left') up.add(Particle(name='G', pos=[0.005, -0.0175, 0.0075], port_particle=True), 'right') down = clone(up) down.rotate(np.pi, [0, 0, 1]) self.add(up, 'up') self.add(down, 'down') self.used = False if orientation is None: orientation = [0, 1, 0] default_direction = [0, 1, 0] if np.array_equal( np.asarray(default_direction), unit_vector(-np.asarray(orientation))): self.rotate(np.pi, [1, 0, 0]) elif np.array_equal( np.asarray(default_direction), unit_vector(np.asarray(orientation))): pass else: normal = np.cross(default_direction, orientation) self.rotate(angle(default_direction, orientation), normal) if anchor: self.translate_to(anchor.pos) self.translate(separation*unit_vector(orientation))
def __init__(self, anchor=None, orientation=None, separation=0): super(Port, self).__init__(name="Port", port_particle=True) self.anchor = anchor default_direction = np.array([0, 1, 0]) if orientation is None: orientation = [0, 1, 0] orientation = np.asarray(orientation) up = Compound(name="subport", port_particle=True) pos = [0.005, 0.0025, -0.0025] up.add(Particle(name="G", pos=pos, port_particle=True), "middle") pos = [0.005, 0.0225, -0.0025] up.add(Particle(name="G", pos=pos, port_particle=True), "top") pos = [-0.015, -0.0075, -0.0025] up.add(Particle(name="G", pos=pos, port_particle=True), "left") pos = [0.005, -0.0175, 0.0075] up.add(Particle(name="G", pos=pos, port_particle=True), "right") down = clone(up) self.add(up, "up") self.add(down, "down") self.used = False if np.allclose(default_direction, unit_vector(-orientation)): down.rotate(np.pi, [0, 0, 1]) self.rotate(np.pi, [0, 0, 1]) elif np.allclose(default_direction, unit_vector(orientation)): down.rotate(np.pi, [0, 0, 1]) else: normal = np.cross(default_direction, orientation) self.rotate(angle(default_direction, orientation), normal) down.rotate(np.pi, normal) if anchor: self.translate_to(anchor.pos) self.translate(separation * unit_vector(orientation))
def direction(self): """The unit vector pointing in the 'direction' of the Port """ return unit_vector(self.xyz_with_ports[1] - self.xyz_with_ports[0])
def direction(self): """The unit vector pointing in the 'direction' of the Port """ return unit_vector(self.xyz_with_ports[1]-self.xyz_with_ports[0])