예제 #1
0
    assert_eq(a.z, b.z)

# and compare it against a reference checked against ascii output
#  va@CP 0 0.311161 0.145214365 0.32167688 0 0 0
#  va@CP 1 -0.0498850037 -0.415475712 0.426996041 0 0 0
#  sb@PM 2 0.5 -0.0639481536 0.170722492 1 0 0
#  sb@PM 3 0.307013747 0.5 -0.174133457 -0 1 0 
# we cannot use model.get_molecule because binary viz data do not contain 
# molecule ids 
for species, data in mol_dict.items():
    if species == 'sb@PM':
        assert len(data) == 4
        assert data[0] == 1
        pos = data[1]
        assert_eq_vec3(
            m.Vec3(pos[0], pos[1], pos[2]),
            m.Vec3(0.5, -0.0639481536, 0.170722492)
        )
        assert_eq_vec3(
            m.Vec3(pos[3], pos[4], pos[5]),
            m.Vec3(0.307013747, 0.5, -0.174133457)
        )
        norms = data[2]
        assert_eq_vec3(
            m.Vec3(norms[0], norms[1], norms[2]),
            m.Vec3(1, 0, 0)
        )
        assert_eq_vec3(
            m.Vec3(norms[3], norms[4], norms[5]),
            m.Vec3(0, 1, 0)
        )
예제 #2
0
import sys
import os


MCELL_PATH = os.environ.get('MCELL_PATH', '')
if MCELL_PATH:
    sys.path.append(os.path.join(MCELL_PATH, 'lib'))
else:
    print("Error: variable MCELL_PATH that is used to find the mcell library was not set.")
    sys.exit(1)
    
import mcell as m

a = m.Vec3(1.5, 2.0, 3)
assert a.x == 1.5
assert a.y == 2.0
assert a.z == 3.0

b = m.Vec3(2.5, 1.0, 2)

assert a != b

c = a + b
assert c == m.Vec3(4.0, 3.0, 5.0)

a.z = 2.0
assert a.z == 2.0

d = a - b
assert d == m.Vec3(-1, 1, 0)
예제 #3
0
    EPS = 1e-6
    assert abs(v1.x - v2.x) < EPS
    assert abs(v1.y - v2.y) < EPS
    assert abs(v1.z - v2.z) < EPS


def check_eq2(v1, v2):
    EPS = 1e-6
    assert abs(v1.x - v2.x) < EPS
    assert abs(v1.y - v2.y) < EPS


va = model.get_molecule(all_ids[0])
#print(va)
assert va.type == m.MoleculeType.VOLUME
check_eq(va.pos3d, m.Vec3(0.057759, 0.0187056, 0.0920891))
assert va.species_id == 3  # may change in the future
assert va.orientation == m.Orientation.NONE
assert not va.geometry_object
assert va.wall_index == -1

sb = model.get_molecule(all_ids[1])
#print(sb)
assert sb.type == m.MoleculeType.SURFACE
check_eq(sb.pos3d, m.Vec3(-0.0134432, 0.111673, 0.125))
check_eq2(sb.pos2d, m.Vec2(0.0883063, 0.0694588))
assert sb.species_id == 4  # may change in the future
assert sb.orientation == m.Orientation.UP
assert sb.geometry_object is model.find_geometry_object('CP')
assert sb.wall_index == 5
예제 #4
0
def rotate_about_normal(normal, displacement):

    axis = m.Vec3(1, 0, 0)
    cos_theta = normal.z
    if cmp_eq(cos_theta, -1.0):
        angle = 180.0
    else:
        axis.x = -normal.y
        axis.y = normal.x
        axis.z = 0

        angle = math.acos(cos_theta) * 180.0 / math.pi

    r1 = np.empty([4, 4])
    r2 = np.empty([4, 4])
    r3 = np.empty([4, 4])

    np_axis = np.array(axis.to_list())
    np_axis = np_axis / np.linalg.norm(np_axis)
    a = np_axis[0]
    b = np_axis[1]
    c = np_axis[2]
    v = math.sqrt(b * b + c * c)

    r1[0][0] = 1
    r1[0][1] = 0
    r1[0][2] = 0
    r1[0][3] = 0
    r1[1][0] = 0
    r1[1][1] = 1
    r1[1][2] = 0
    r1[1][3] = 0
    r1[2][0] = 0
    r1[2][1] = 0
    r1[2][2] = 1
    r1[2][3] = 0
    r1[3][0] = 0
    r1[3][1] = 0
    r1[3][2] = 0
    r1[3][3] = 1

    if v != 0.0:
        r1[1][1] = c / v
        r1[1][2] = b / v
        r1[2][1] = -b / v
        r1[2][2] = c / v

    r2[0][0] = v
    r2[0][1] = 0
    r2[0][2] = a
    r2[0][3] = 0
    r2[1][0] = 0
    r2[1][1] = 1
    r2[1][2] = 0
    r2[1][3] = 0
    r2[2][0] = -a
    r2[2][1] = 0
    r2[2][2] = v
    r2[2][3] = 0
    r2[3][0] = 0
    r2[3][1] = 0
    r2[3][2] = 0
    r2[3][3] = 1

    rad = math.pi / 180.0
    r3[0][0] = math.cos(angle * rad)
    r3[0][1] = math.sin(angle * rad)
    r3[0][2] = 0
    r3[0][3] = 0
    r3[1][0] = -math.sin(angle * rad)
    r3[1][1] = math.cos(angle * rad)
    r3[1][2] = 0
    r3[1][3] = 0
    r3[2][0] = 0
    r3[2][1] = 0
    r3[2][2] = 1
    r3[2][3] = 0
    r3[3][0] = 0
    r3[3][1] = 0
    r3[3][2] = 0
    r3[3][3] = 1

    #om = r1.dot(r2)
    om = np.matmul(r1, r2)
    om = np.matmul(om, r3)

    r2[0][2] = -a
    r2[2][0] = a

    if v != 0:
        r1[1][2] = -b / v
        r1[2][1] = b / v

    om = np.matmul(om, r2)
    om = np.matmul(om, r1)

    l = displacement.to_list()
    l.append(1.0)
    #print(l)
    np_displ = np.array(l)
    #print(np_displ)
    res = np.matmul(np_displ, om)

    return m.Vec3(res[0], res[1], res[2])