Example #1
0
def main():
    #t = [1,2,3,[4,5],[],[6]]
    #print(flatten(t))

    #Simple test case, without nesting
    s1 = 'CH3NH2SH'
    t1 = set_bonds(parsing.number_list(parsing.make_list(
        parsing.remove_h(s1))))

    #Complicated example, with nesting and electron pairs
    s2 = 'CH3N(CH2NHOH)SH'
    t2 = set_bonds(parsing.number_list(parsing.make_list(
        parsing.remove_h(s2))))

    #print fill_hydrogens(flatten(t2))

    #Another simple example, this time with no electron pairs
    s3 = 'CH3CH2CH3'
    t3 = set_bonds(parsing.number_list(parsing.make_list(
        parsing.remove_h(s3))))

    #An extremely simple test case...
    s4 = 'CH4'
    t4 = set_bonds(parsing.number_list(parsing.make_list(
        parsing.remove_h(s4))))
    print fill_hydrogens(flatten(t4))
Example #2
0
def main():
    t = [1,2,3,[4,5],[],[6]]
    print flatten(t)

    s1 = 'CH3CH2CH3'
    print 's1:',
    print parsing.remove_h(s1)
    print parsing.make_list(parsing.remove_h(s1))
    print parsing.number_list(parsing.make_list(parsing.remove_h(s1)))

    print set_bonds(parsing.number_list(parsing.make_list(parsing.remove_h(s1))))
Example #3
0
def main():
    t = [1, 2, 3, [4, 5], [], [6]]
    print flatten(t)

    s1 = 'CH3CH2CH3'
    print 's1:',
    print parsing.remove_h(s1)
    print parsing.make_list(parsing.remove_h(s1))
    print parsing.number_list(parsing.make_list(parsing.remove_h(s1)))

    print set_bonds(
        parsing.number_list(parsing.make_list(parsing.remove_h(s1))))
Example #4
0
def main():
    t = [1,2,3,[4,5],[],[6]]
    print(flatten(t))

    #set_bonds() works for chains...
    s1 = 'CH3NH2SH'
    t1 = parsing.number_list(parsing.make_list(parsing.remove_h(s1)))
    print('s1: ')
    print(t1)
    print(set_bonds(t1))
    
    #...but not for nested chains. It only evaluates the first atom in the chain, then ignores the rest! We should fix this.
    s2 = 'CH3NH(CHNHOH)SH'

    t2 = parsing.number_list(parsing.make_list(parsing.remove_h(s1)))
    print('s2: ')
    print(t2)
    print(set_bonds(t2))
Example #5
0
def main():
    t = [1, 2, 3, [4, 5], [], [6]]
    print(flatten(t))

    #set_bonds() works for chains...
    s1 = 'CH3NH2SH'
    t1 = parsing.number_list(parsing.make_list(parsing.remove_h(s1)))
    print('s1: ')
    print(t1)
    print(set_bonds(t1))

    #...but not for nested chains. It only evaluates the first atom in the chain, then ignores the rest! We should fix this.
    s2 = 'CH3NH(CHNHOH)SH'

    t2 = parsing.number_list(parsing.make_list(parsing.remove_h(s1)))
    print('s2: ')
    print(t2)
    print(set_bonds(t2))
Example #6
0
def main():
    #t = [1,2,3,[4,5],[],[6]]
    #print(flatten(t))

    #Simple test case, without nesting
    #s1 = 'CH3NH2SH'
    #t1 = set_bonds(parsing.number_list(parsing.make_list(parsing.remove_h(s1))))

    # Complicated example, with nesting and electron pairs
    s2 = 'CH3N(CH2NHOH)SH'
    t2 = set_bonds(parsing.number_list(parsing.make_list(parsing.remove_h(s2))))

    print(fill_hydrogens(flatten(t2)))
Example #7
0
def main():
    #t = [1,2,3,[4,5],[],[6]]
    #print(flatten(t))

    #Simple test case, without nesting
    s1 = 'CH3NH2SH'
    t1 = set_bonds(parsing.number_list(parsing.make_list(parsing.remove_h(s1))))

    #Complicated example, with nesting and electron pairs
    s2 = 'CH3N(CH2NHOH)SH'
    t2 = set_bonds(parsing.number_list(parsing.make_list(parsing.remove_h(s2))))

    #print fill_hydrogens(flatten(t2))

    #Another simple example, this time with no electron pairs
    s3 = 'CH3CH2CH3'
    t3 = set_bonds(parsing.number_list(parsing.make_list(parsing.remove_h(s3))))

    #An extremely simple test case...
    s4 = 'CH4'
    t4 = set_bonds(parsing.number_list(parsing.make_list(parsing.remove_h(s4))))
    print fill_hydrogens(flatten(t4))
Example #8
0
def main():
    #t = [1,2,3,[4,5],[],[6]]
    #print(flatten(t))

    #Simple test case, without nesting
    #s1 = 'CH3NH2SH'
    #t1 = set_bonds(parsing.number_list(parsing.make_list(parsing.remove_h(s1))))

    # Complicated example, with nesting and electron pairs
    s2 = 'CH3N(CH2NHOH)SH'
    t2 = set_bonds(parsing.number_list(parsing.make_list(
        parsing.remove_h(s2))))

    print(fill_hydrogens(flatten(t2)))
    if len(bonds) == 3:
        phi = theta + (2 * math.pi / 3)
        phi2 = phi + (2 * math.pi / 3)
        if isinstance(bonds[1], Atom):
            atom.bonds[1].pos = [
                atom.pos[0] - b * math.cos(phi),
                atom.pos[1] - b * math.sin(phi), atom.pos[2]
            ]
        if isinstance(bonds[2], Atom):
            atom.bonds[2].pos = [
                atom.pos[0] - b * math.cos(phi2),
                atom.pos[1] - b * math.sin(phi2), atom.pos[2]
            ]

    if len(bonds) == 4:
        print("fix this")


if __name__ == "__main__":
    s1 = 'CH3CH2CH(CH2CH3)CH2CH3'

    t = set_bonds(number_list(make_list(remove_h(s1))))
    t[1].pos = [2, 3, 0]
    set_pos(t)

    t2 = flatten(t)

    for atom in t2:
        print atom
        print atom.pos
    
    if len(bonds) == 3:
        phi = theta + (2*math.pi/3)
        phi2 = phi + (2*math.pi/3)
        if isinstance(bonds[1],Atom):
            atom.bonds[1].pos = [atom.pos[0] - b*math.cos(phi),atom.pos[1] - b*math.sin(phi),atom.pos[2]]
        if isinstance(bonds[2],Atom):
            atom.bonds[2].pos = [atom.pos[0] - b*math.cos(phi2),atom.pos[1]-b*math.sin(phi2), atom.pos[2]]
    
    if len(bonds) ==4:
        print ("fix this")
        
if __name__ == "__main__":
    s1 = 'CH3CH2CH(CH2CH3)CH2CH3'

    t = set_bonds(number_list(make_list(remove_h(s1))))
    t[1].pos = [2,3,0]
    set_pos(t)

    t2 = flatten(t)
    
    for atom in t2:
        print atom
        print atom.pos
        
    
    
    
        
    
def makeMolecule(formula):    
    
    #Creates list of atoms with appropriate bonds
    t = fill_hydrogens(set_bonds(number_list(make_list(remove_h(formula)))))
    
    #Base bond length
    b = 3

    if isinstance(t[0], Carbon):
        t[1].pos = ((0,b*sqrt(t[0].radius)*sqrt(t[1].radius),0))
    set_pos(t,b)
    t2 = flatten(t)
  
    bpy.ops.scene.delete()
    bpy.ops.scene.new(type = 'NEW')
    
    colors = {}
    
    #Draws atom with appropriate color and size
    for atom in t2:
        elem = (atom.name[0:1])
        
        #maps element to an appropriate material
        colors[elem] = colors.get(elem, makeMaterial(elem,tuple(atom.color), (1,1,1),1))
        
        #Draws atom and sets its material
        bpy.ops.mesh.primitive_uv_sphere_add(location = atom.pos, size = atom.radius*1)
        setMaterial(bpy.context.object, colors[(atom.name[0:1])])
        bonds = atom.bonds
        
        #Draws cylinders between atoms
        for i in range(0, len(bonds)):
            if isinstance(bonds[i], Atom):
                hyd = (bonds[i].name[0:1])
                list = [atom, bonds[i]]
                bpy.ops.mesh.primitive_uv_sphere_add(location = bonds[i].pos, size = bonds[i].radius*1)
                colors[hyd] = colors.get(hyd, makeMaterial(hyd,tuple(bonds[i].color), (1,1,1),1))
                setMaterial(bpy.context.object, colors[hyd])
                
                # Create curve 
                draw_curve = bpy.data.curves.new('draw_curve','CURVE')
                draw_curve.dimensions = '3D'
                spline = draw_curve.splines.new('BEZIER')
                spline.bezier_points.add(len(list)-1)
                curve = bpy.data.objects.new('curve',draw_curve)
                bpy.context.scene.objects.link(curve)
            
                # Curve settings for new curve
                draw_curve.resolution_u = 64
                draw_curve.fill_mode = 'FULL'
                draw_curve.bevel_depth = 0.3
                draw_curve.bevel_resolution = 5
        
                # Assign bezier points to selection object locations
                for i in range(len(list)):
                    p = spline.bezier_points[i]
                    p.co = list[i].pos
                    p.handle_right_type="VECTOR"
                    p.handle_left_type="VECTOR"
                
                bpy.context.scene.objects.active = curve
                bpy.ops.object.mode_set(mode='OBJECT')