Chempy: Difference between revisions

From PyMOLWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 129: Line 129:
Example
Example
<source lang="python">
<source lang="python">
from chempy import cpv
PyMOL>a = [1.2 , 3.4, 4.5]
PyMOL>a = [1.2 , 3.4, 4.5]
PyMOL>b = [2.2 , 4.4, 5.5]
PyMOL>b = [2.2 , 4.4, 5.5]

Latest revision as of 05:01, 31 August 2011

Chempy is a python-importable module that can be used to write PyMOL-executable scripts.

from chempy import cpv
help(cpv)

    # Generic vector and matrix routines for 3-Space
    # Assembled for usage in PyMOL and Chemical Python
    #
    # Assumes row-major matrices and arrays
    # [ [vector 1], [vector 2], [vector 3] ]
    #
    # Raises ValueError when given bad input

FUNCTIONS
    add(v1, v2)
        #------------------------------------------------------------------------------
    
    average(v1, v2)
        #------------------------------------------------------------------------------
    
    cross_product(v1, v2)
        #------------------------------------------------------------------------------
    
    distance(v1, v2)
        #------------------------------------------------------------------------------
    
    distance_sq(v1, v2)
        #------------------------------------------------------------------------------
    
    dot_product(v1, v2)
        #------------------------------------------------------------------------------
    
    fit(target_array, source_array)
        fit(target_array, source_array) -> (t1, t2, rot_mtx, rmsd) [fit_result]
        
        Calculates the translation vectors and rotation matrix required
        to superimpose source_array onto target_array.  Original arrays are
        not modified.  NOTE: Currently assumes 3-dimensional coordinates
        
        t1,t2 are vectors from origin to centers of mass...
    
    fit_apply(fit_result, vec_array)
        fit_apply(fir_result,vec_array) -> vec_array
        
        Applies a fit result to an array of vectors
    
    get_angle(v1, v2)
        #------------------------------------------------------------------------------
    
    get_angle_formed_by(p1, p2, p3)
        #------------------------------------------------------------------------------
    
    get_identity()
        #------------------------------------------------------------------------------
    
    get_null()
        #------------------------------------------------------------------------------
    
    get_system2(x, y)
        #------------------------------------------------------------------------------
    
    inverse_transform(m, v)
        #------------------------------------------------------------------------------
    
    length(v)
        #------------------------------------------------------------------------------
    
    multiply(m1, m2)
        #------------------------------------------------------------------------------
    
    negate(v)
        #------------------------------------------------------------------------------
    
    normalize(v)
        #------------------------------------------------------------------------------
    
    normalize_failsafe(v)
        #------------------------------------------------------------------------------
    
    project(v, n)
        #------------------------------------------------------------------------------
    
    random_displacement(v, radius)
        #------------------------------------------------------------------------------
    
    random_sphere(v, radius)
        #------------------------------------------------------------------------------
    
    random_vector()
        #------------------------------------------------------------------------------
    
    remove_component(v, n)
        #------------------------------------------------------------------------------
    
    reverse(v)
        #------------------------------------------------------------------------------
    
    rotation_matrix(angle, axis)
        #------------------------------------------------------------------------------
    
    scale(v, factor)
        #------------------------------------------------------------------------------
    
    scale_system(s, factor)
        #------------------------------------------------------------------------------
    
    sub(v1, v2)
        #------------------------------------------------------------------------------
    
    transform(m, v)
        #------------------------------------------------------------------------------
    
    transform_about_point(m, v, p)
        #------------------------------------------------------------------------------
    
    transform_array(rot_mtx, vec_array)
        transform_array( matrix, vector_array ) -> vector_array
    
    translate_array(trans_vec, vec_array)
        translate_array(trans_vec,vec_array) -> vec_array
        
        Adds 'mult'*'trans_vec' to each element in vec_array, and returns
        the translated vector.
    
    transpose(m)
        #------------------------------------------------------------------------------

Example

from chempy import cpv
PyMOL>a = [1.2 , 3.4, 4.5]
PyMOL>b = [2.2 , 4.4, 5.5]
PyMOL>c = cpv.add(a,b)
PyMOL>print c
[3.4000000000000004, 7.800000000000001, 10.0]