idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
59,800 | def serialize ( self ) : data = super ( Note , self ) . serialize ( ) data . update ( { "verb" : "post" , "object" : { "objectType" : self . object_type , "content" : self . content , } } ) if self . display_name : data [ "object" ] [ "displayName" ] = self . display_name return data | Converts the post to something compatible with json . dumps |
59,801 | def context ( self ) : type = "client_associate" if self . key is None else "client_update" data = { "type" : type , "application_type" : self . type , } if self . key : data [ "client_id" ] = self . key data [ "client_secret" ] = self . secret if self . name : data [ "application_name" ] = self . name if self . logo :... | Provides request context |
59,802 | def request ( self , server = None ) : request = { "headers" : { "Content-Type" : "application/json" } , "timeout" : self . _pump . timeout , "data" : self . context , } url = "{proto}://{server}/{endpoint}" . format ( proto = self . _pump . protocol , server = server or self . server , endpoint = self . ENDPOINT , ) r... | Sends the request |
59,803 | def register ( self , server = None ) : if ( self . key or self . secret ) : return self . update ( ) server_data = self . request ( server ) self . key = server_data [ "client_id" ] self . secret = server_data [ "client_secret" ] self . expirey = server_data [ "expires_at" ] | Registers the client with the Pump API retrieving the id and secret |
59,804 | def update ( self ) : error = "" if self . key is None : error = "To update a client you need to provide a key" if self . secret is None : error = "To update a client you need to provide the secret" if error : raise ClientException ( error ) self . request ( ) return True | Updates the information the Pump server has about the client |
59,805 | def compile_extensions ( macros , compat = False ) : import distutils . sysconfig import distutils . ccompiler import tempfile import shutil from textwrap import dedent libraries = [ 'rrd' ] include_dirs = [ package_dir , '/usr/local/include' ] library_dirs = [ '/usr/local/lib' ] compiler_args = dict ( libraries = libr... | Compiler subroutine to test whether some functions are available on the target system . Since the rrdtool headers shipped with most packages do not disclose any versioning information we cannot test whether a given function is available that way . Instead use this to manually try to compile code and see if it works . |
59,806 | def add ( self , obj ) : activity = { "verb" : "add" , "object" : { "objectType" : obj . object_type , "id" : obj . id } , "target" : { "objectType" : self . object_type , "id" : self . id } } self . _post_activity ( activity ) self . _members = None | Adds a member to the collection . |
59,807 | def remove ( self , obj ) : activity = { "verb" : "remove" , "object" : { "objectType" : obj . object_type , "id" : obj . id } , "target" : { "objectType" : self . object_type , "id" : self . id } } self . _post_activity ( activity ) self . _members = None | Removes a member from the collection . |
59,808 | def _post_activity ( self , activity , unserialize = True ) : feed_url = "{proto}://{server}/api/user/{username}/feed" . format ( proto = self . _pump . protocol , server = self . _pump . client . server , username = self . _pump . client . nickname ) data = self . _pump . request ( feed_url , method = "POST" , data = ... | Posts a activity to feed |
59,809 | def _add_links ( self , links , key = "href" , proxy_key = "proxyURL" , endpoints = None ) : if endpoints is None : endpoints = [ "likes" , "replies" , "shares" , "self" , "followers" , "following" , "lists" , "favorites" , "members" ] if links . get ( "links" ) : for endpoint in links [ 'links' ] : if isinstance ( lin... | Parses and adds block of links |
59,810 | def _set_people ( self , people ) : if hasattr ( people , "object_type" ) : people = [ people ] elif hasattr ( people , "__iter__" ) : people = list ( people ) return people | Sets who the object is sent to |
59,811 | def from_file ( self , filename ) : mimetype = mimetypes . guess_type ( filename ) [ 0 ] or "application/octal-stream" headers = { "Content-Type" : mimetype , "Content-Length" : str ( os . path . getsize ( filename ) ) , } file_data = self . _pump . request ( "/api/user/{0}/uploads" . format ( self . _pump . client . n... | Uploads a file from a filename on your system . |
59,812 | def unserialize ( self , data ) : if "author" not in data [ "object" ] : data [ "object" ] [ "author" ] = data [ "actor" ] for key in [ "to" , "cc" , "bto" , "bcc" ] : if key not in data [ "object" ] and key in data : data [ "object" ] [ key ] = data [ key ] Mapper ( pypump = self . _pump ) . parse_map ( self , data = ... | From JSON - > Activity object |
59,813 | def create_store ( self ) : if self . store_class is not None : return self . store_class . load ( self . client . webfinger , self ) raise NotImplementedError ( "You need to specify PyPump.store_class or override PyPump.create_store method." ) | Creates store object |
59,814 | def _build_url ( self , endpoint ) : server = None if "://" in endpoint : server , endpoint = self . _deconstruct_url ( endpoint ) endpoint = endpoint . lstrip ( "/" ) url = "{proto}://{server}/{endpoint}" . format ( proto = self . protocol , server = self . client . server if server is None else server , endpoint = en... | Returns a fully qualified URL |
59,815 | def _deconstruct_url ( self , url ) : url = url . split ( "://" , 1 ) [ - 1 ] server , endpoint = url . split ( "/" , 1 ) return ( server , endpoint ) | Breaks down URL and returns server and endpoint |
59,816 | def _add_client ( self , url , key = None , secret = None ) : if "://" in url : server , endpoint = self . _deconstruct_url ( url ) else : server = url if server not in self . _server_cache : if not ( key and secret ) : client = Client ( webfinger = self . client . webfinger , name = self . client . name , type = self ... | Creates Client object with key and secret for server and adds it to _server_cache if it doesnt already exist |
59,817 | def request ( self , endpoint , method = "GET" , data = "" , raw = False , params = None , retries = None , client = None , headers = None , timeout = None , ** kwargs ) : retries = self . retries if retries is None else retries timeout = self . timeout if timeout is None else timeout if client is None : client = self ... | Make request to endpoint with OAuth . Returns dictionary with response data . |
59,818 | def oauth_request ( self ) : self . _server_tokens = self . request_token ( ) self . store [ "oauth-request-token" ] = self . _server_tokens [ "token" ] self . store [ "oauth-request-secret" ] = self . _server_tokens [ "token_secret" ] result = self . verifier_callback ( self . construct_oauth_url ( ) ) if result is no... | Makes a oauth connection |
59,819 | def construct_oauth_url ( self ) : response = self . _requester ( requests . head , "{0}://{1}/" . format ( self . protocol , self . client . server ) , allow_redirects = False ) if response . is_redirect : server = response . headers [ 'location' ] else : server = response . url path = "oauth/authorize?oauth_token={to... | Constructs verifier OAuth URL |
59,820 | def setup_oauth_client ( self , url = None ) : if url and "://" in url : server , endpoint = self . _deconstruct_url ( url ) else : server = self . client . server if server not in self . _server_cache : self . _add_client ( server ) if server == self . client . server : self . oauth = OAuth1 ( client_key = self . stor... | Sets up client for requests to pump |
59,821 | def request_token ( self ) : client = OAuth1 ( client_key = self . _server_cache [ self . client . server ] . key , client_secret = self . _server_cache [ self . client . server ] . secret , callback_uri = self . callback , ) request = { "auth" : client } response = self . _requester ( requests . post , "oauth/request_... | Gets OAuth request token |
59,822 | def request_access ( self , verifier ) : client = OAuth1 ( client_key = self . _server_cache [ self . client . server ] . key , client_secret = self . _server_cache [ self . client . server ] . secret , resource_owner_key = self . store [ "oauth-request-token" ] , resource_owner_secret = self . store [ "oauth-request-s... | Get OAuth access token so we can make requests |
59,823 | def logged_in ( self ) : if "oauth-access-token" not in self . store : return False response = self . request ( "/api/whoami" , allow_redirects = False ) if response . status_code != 302 : return False if response . headers [ "location" ] != self . me . links [ "self" ] : return False return True | Return boolean if is logged in |
59,824 | def cudnnCreate ( ) : handle = ctypes . c_void_p ( ) status = _libcudnn . cudnnCreate ( ctypes . byref ( handle ) ) cudnnCheckStatus ( status ) return handle . value | Initialize cuDNN . |
59,825 | def cudnnDestroy ( handle ) : status = _libcudnn . cudnnDestroy ( ctypes . c_void_p ( handle ) ) cudnnCheckStatus ( status ) | Release cuDNN resources . |
59,826 | def cudnnSetStream ( handle , id ) : status = _libcudnn . cudnnSetStream ( handle , id ) cudnnCheckStatus ( status ) | Set current cuDNN library stream . |
59,827 | def cudnnGetStream ( handle ) : id = ctypes . c_void_p ( ) status = _libcudnn . cudnnGetStream ( handle , ctypes . byref ( id ) ) cudnnCheckStatus ( status ) return id . value | Get current cuDNN library stream . |
59,828 | def cudnnCreateTensorDescriptor ( ) : tensor = ctypes . c_void_p ( ) status = _libcudnn . cudnnCreateTensorDescriptor ( ctypes . byref ( tensor ) ) cudnnCheckStatus ( status ) return tensor . value | Create a Tensor descriptor object . |
59,829 | def cudnnSetTensor4dDescriptor ( tensorDesc , format , dataType , n , c , h , w ) : status = _libcudnn . cudnnSetTensor4dDescriptor ( tensorDesc , format , dataType , n , c , h , w ) cudnnCheckStatus ( status ) | Initialize a previously created Tensor 4D object . |
59,830 | def cudnnSetTensor4dDescriptorEx ( tensorDesc , dataType , n , c , h , w , nStride , cStride , hStride , wStride ) : status = _libcudnn . cudnnSetTensor4dDescriptorEx ( tensorDesc , dataType , n , c , h , w , nStride , cStride , hStride , wStride ) cudnnCheckStatus ( status ) | Initialize a Tensor descriptor object with strides . |
59,831 | def cudnnGetTensor4dDescriptor ( tensorDesc ) : dataType = ctypes . c_int ( ) n = ctypes . c_int ( ) c = ctypes . c_int ( ) h = ctypes . c_int ( ) w = ctypes . c_int ( ) nStride = ctypes . c_int ( ) cStride = ctypes . c_int ( ) hStride = ctypes . c_int ( ) wStride = ctypes . c_int ( ) status = _libcudnn . cudnnGetTenso... | Get parameters of a Tensor descriptor object . |
59,832 | def cudnnCreateFilterDescriptor ( ) : wDesc = ctypes . c_void_p ( ) status = _libcudnn . cudnnCreateFilterDescriptor ( ctypes . byref ( wDesc ) ) cudnnCheckStatus ( status ) return wDesc . value | Create a filter descriptor . |
59,833 | def cudnnSetFilter4dDescriptor ( wDesc , dataType , format , k , c , h , w ) : status = _libcudnn . cudnnSetFilter4dDescriptor ( wDesc , dataType , format , k , c , h , w ) cudnnCheckStatus ( status ) | Initialize a filter descriptor . |
59,834 | def cudnnGetFilter4dDescriptor ( wDesc ) : dataType = ctypes . c_int ( ) format = ctypes . c_int ( ) k = ctypes . c_int ( ) c = ctypes . c_int ( ) h = ctypes . c_int ( ) w = ctypes . c_int ( ) status = _libcudnn . cudnnGetFilter4dDescriptor ( wDesc , ctypes . byref ( dataType ) , ctypes . byref ( format ) , ctypes . by... | Get parameters of filter descriptor . |
59,835 | def cudnnCreateConvolutionDescriptor ( ) : convDesc = ctypes . c_void_p ( ) status = _libcudnn . cudnnCreateConvolutionDescriptor ( ctypes . byref ( convDesc ) ) cudnnCheckStatus ( status ) return convDesc . value | Create a convolution descriptor . |
59,836 | def cudnnSetConvolution2dDescriptor ( convDesc , pad_h , pad_w , u , v , dilation_h , dilation_w , mode , computeType ) : status = _libcudnn . cudnnSetConvolution2dDescriptor ( convDesc , pad_h , pad_w , u , v , dilation_h , dilation_w , mode , computeType ) cudnnCheckStatus ( status ) | Initialize a convolution descriptor . |
59,837 | def cudnnGetConvolution2dDescriptor ( convDesc ) : pad_h = ctypes . c_int ( ) pad_w = ctypes . c_int ( ) u = ctypes . c_int ( ) v = ctypes . c_int ( ) dilation_h = ctypes . c_int ( ) dilation_w = ctypes . c_int ( ) mode = ctypes . c_int ( ) computeType = ctypes . c_int ( ) status = _libcudnn . cudnnGetConvolution2dDesc... | Get a convolution descriptor . |
59,838 | def cudnnGetConvolution2dForwardOutputDim ( convDesc , inputTensorDesc , wDesc ) : n = ctypes . c_int ( ) c = ctypes . c_int ( ) h = ctypes . c_int ( ) w = ctypes . c_int ( ) status = _libcudnn . cudnnGetConvolution2dForwardOutputDim ( convDesc , inputTensorDesc , wDesc , ctypes . byref ( n ) , ctypes . byref ( c ) , c... | Return the dimensions of the output tensor given a convolution descriptor . |
59,839 | def cudnnGetConvolutionForwardAlgorithm ( handle , srcDesc , wDesc , convDesc , destDesc , preference , memoryLimitInbytes ) : algo = ctypes . c_int ( ) status = _libcudnn . cudnnGetConvolutionForwardAlgorithm ( handle , srcDesc , wDesc , convDesc , destDesc , preference , ctypes . c_size_t ( memoryLimitInbytes ) , cty... | This function returns the best algorithm to choose for the forward convolution depending on the critera expressed in the cudnnConvolutionFwdPreference_t enumerant . |
59,840 | def cudnnGetConvolutionForwardWorkspaceSize ( handle , srcDesc , wDesc , convDesc , destDesc , algo ) : sizeInBytes = ctypes . c_size_t ( ) status = _libcudnn . cudnnGetConvolutionForwardWorkspaceSize ( handle , srcDesc , wDesc , convDesc , destDesc , algo , ctypes . byref ( sizeInBytes ) ) cudnnCheckStatus ( status ) ... | This function returns the amount of GPU memory workspace the user needs to allocate to be able to call cudnnConvolutionForward with the specified algorithm . |
59,841 | def cudnnSoftmaxForward ( handle , algorithm , mode , alpha , srcDesc , srcData , beta , destDesc , destData ) : dataType = cudnnGetTensor4dDescriptor ( destDesc ) [ 0 ] if dataType == cudnnDataType [ 'CUDNN_DATA_DOUBLE' ] : alphaRef = ctypes . byref ( ctypes . c_double ( alpha ) ) betaRef = ctypes . byref ( ctypes . c... | This routing computes the softmax function |
59,842 | def cudnnCreatePoolingDescriptor ( ) : poolingDesc = ctypes . c_void_p ( ) status = _libcudnn . cudnnCreatePoolingDescriptor ( ctypes . byref ( poolingDesc ) ) cudnnCheckStatus ( status ) return poolingDesc . value | Create pooling descriptor . |
59,843 | def cudnnSetPooling2dDescriptor ( poolingDesc , mode , windowHeight , windowWidth , verticalPadding , horizontalPadding , verticalStride , horizontalStride ) : status = _libcudnn . cudnnSetPooling2dDescriptor ( poolingDesc , mode , windowHeight , windowWidth , verticalPadding , horizontalPadding , verticalStride , hori... | Initialize a 2D pooling descriptor . |
59,844 | def cudnnGetPooling2dDescriptor ( poolingDesc ) : mode = ctypes . c_int ( ) windowHeight = ctypes . c_int ( ) windowWidth = ctypes . c_int ( ) verticalPadding = ctypes . c_int ( ) horizontalPadding = ctypes . c_int ( ) verticalStride = ctypes . c_int ( ) horizontalStride = ctypes . c_int ( ) status = _libcudnn . cudnnG... | This function queries a previously created pooling descriptor object . |
59,845 | def cudnnActivationBackward ( handle , mode , alpha , srcDesc , srcData , srcDiffDesc , srcDiffData , destDesc , destData , beta , destDiffDesc , destDiffData ) : dataType = cudnnGetTensor4dDescriptor ( destDesc ) [ 0 ] if dataType == cudnnDataType [ 'CUDNN_DATA_DOUBLE' ] : alphaRef = ctypes . byref ( ctypes . c_double... | Gradient of activation function . |
59,846 | def __prefix_key ( self , key ) : if self . prefix is None : return key if key . startswith ( self . prefix + "-" ) : return key return "{0}-{1}" . format ( self . prefix , key ) | This will add the prefix to the key if one exists on the store |
59,847 | def export ( self ) : data = { } for key , value in self . items ( ) : data [ key ] = value return data | Exports as dictionary |
59,848 | def save ( self ) : if self . filename is None : raise StoreException ( "Filename must be set to write store to disk" ) filename = "{filename}.{date}.tmp" . format ( filename = self . filename , date = datetime . datetime . utcnow ( ) . strftime ( '%Y-%m-%dT%H_%M_%S.%f' ) ) mode = stat . S_IRUSR | stat . S_IWUSR fd = o... | Saves dictionary to disk in JSON format . |
59,849 | def get_filename ( cls ) : config_home = os . environ . get ( "XDG_CONFIG_HOME" , "~/.config" ) config_home = os . path . expanduser ( config_home ) base_path = os . path . join ( config_home , "PyPump" ) if not os . path . isdir ( base_path ) : os . makedirs ( base_path ) return os . path . join ( base_path , "credent... | Gets filename of store on disk |
59,850 | def load ( cls , webfinger , pypump ) : filename = cls . get_filename ( ) if os . path . isfile ( filename ) : data = open ( filename ) . read ( ) data = json . loads ( data ) store = cls ( data , filename = filename ) else : store = cls ( filename = filename ) store . prefix = webfinger return store | Load JSON from disk into store object |
59,851 | def pause ( message = 'Press any key to continue . . . ' ) : if message is not None : print ( message , end = '' ) sys . stdout . flush ( ) getch ( ) print ( ) | Prints the specified message if it s not None and waits for a keypress . |
59,852 | def covalent_bonds ( atoms , threshold = 1.1 ) : bonds = [ ] for a , b in atoms : bond_distance = ( element_data [ a . element . title ( ) ] [ 'atomic radius' ] + element_data [ b . element . title ( ) ] [ 'atomic radius' ] ) / 100 dist = distance ( a . _vector , b . _vector ) if dist <= bond_distance * threshold : bon... | Returns all the covalent bonds in a list of Atom pairs . |
59,853 | def find_covalent_bonds ( ampal , max_range = 2.2 , threshold = 1.1 , tag = True ) : sectors = gen_sectors ( ampal . get_atoms ( ) , max_range * 1.1 ) bonds = [ ] for sector in sectors . values ( ) : atoms = itertools . combinations ( sector , 2 ) bonds . extend ( covalent_bonds ( atoms , threshold = threshold ) ) bond... | Finds all covalent bonds in the AMPAL object . |
59,854 | def generate_covalent_bond_graph ( covalent_bonds ) : bond_graph = networkx . Graph ( ) for inter in covalent_bonds : bond_graph . add_edge ( inter . a , inter . b ) return bond_graph | Generates a graph of the covalent bond network described by the interactions . |
59,855 | def generate_bond_subgraphs_from_break ( bond_graph , atom1 , atom2 ) : bond_graph . remove_edge ( atom1 , atom2 ) try : subgraphs = list ( networkx . connected_component_subgraphs ( bond_graph , copy = False ) ) finally : bond_graph . add_edge ( atom1 , atom2 ) return subgraphs | Splits the bond graph between two atoms to producing subgraphs . |
59,856 | def cap ( v , l ) : s = str ( v ) return s if len ( s ) <= l else s [ - l : ] | Shortens string is above certain length . |
59,857 | def find_atoms_within_distance ( atoms , cutoff_distance , point ) : return [ x for x in atoms if distance ( x , point ) <= cutoff_distance ] | Returns atoms within the distance from the point . |
59,858 | def centre_of_atoms ( atoms , mass_weighted = True ) : points = [ x . _vector for x in atoms ] if mass_weighted : masses = [ x . mass for x in atoms ] else : masses = [ ] return centre_of_mass ( points = points , masses = masses ) | Returns centre point of any list of atoms . |
59,859 | def assign_force_field ( self , ff , mol2 = False ) : if hasattr ( self , 'ligands' ) : atoms = self . get_atoms ( ligands = True , inc_alt_states = True ) else : atoms = self . get_atoms ( inc_alt_states = True ) for atom in atoms : w_str = None a_ff_id = None if atom . element == 'H' : continue elif atom . ampal_pare... | Assigns force field parameters to Atoms in the AMPAL object . |
59,860 | def update_ff ( self , ff , mol2 = False , force_ff_assign = False ) : aff = False if force_ff_assign : aff = True elif 'assigned_ff' not in self . tags : aff = True elif not self . tags [ 'assigned_ff' ] : aff = True if aff : self . assign_force_field ( ff , mol2 = mol2 ) return | Manages assigning the force field parameters . |
59,861 | def get_internal_energy ( self , assign_ff = True , ff = None , mol2 = False , force_ff_assign = False ) : if not ff : ff = global_settings [ 'buff' ] [ 'force_field' ] if assign_ff : self . update_ff ( ff , mol2 = mol2 , force_ff_assign = force_ff_assign ) interactions = find_intra_ampal ( self , ff . distance_cutoff ... | Calculates the internal energy of the AMPAL object . |
59,862 | def rotate ( self , angle , axis , point = None , radians = False , inc_alt_states = True ) : q = Quaternion . angle_and_axis ( angle = angle , axis = axis , radians = radians ) for atom in self . get_atoms ( inc_alt_states = inc_alt_states ) : atom . _vector = q . rotate_vector ( v = atom . _vector , point = point ) r... | Rotates every atom in the AMPAL object . |
59,863 | def translate ( self , vector , inc_alt_states = True ) : vector = numpy . array ( vector ) for atom in self . get_atoms ( inc_alt_states = inc_alt_states ) : atom . _vector += vector return | Translates every atom in the AMPAL object . |
59,864 | def rmsd ( self , other , backbone = False ) : assert type ( self ) == type ( other ) if backbone and hasattr ( self , 'backbone' ) : points1 = self . backbone . get_atoms ( ) points2 = other . backbone . get_atoms ( ) else : points1 = self . get_atoms ( ) points2 = other . get_atoms ( ) points1 = [ x . _vector for x i... | Calculates the RMSD between two AMPAL objects . |
59,865 | def append ( self , item ) : if isinstance ( item , Monomer ) : self . _monomers . append ( item ) else : raise TypeError ( 'Only Monomer objects can be appended to an Polymer.' ) return | Appends a Monomer to the Polymer . |
59,866 | def extend ( self , polymer ) : if isinstance ( polymer , Polymer ) : self . _monomers . extend ( polymer ) else : raise TypeError ( 'Only Polymer objects may be merged with a Polymer using unary operator "+".' ) return | Extends the Polymer with the contents of another Polymer . |
59,867 | def get_monomers ( self , ligands = True ) : if ligands and self . ligands : monomers = self . _monomers + self . ligands . _monomers else : monomers = self . _monomers return iter ( monomers ) | Retrieves all the Monomers from the AMPAL object . |
59,868 | def get_atoms ( self , ligands = True , inc_alt_states = False ) : if ligands and self . ligands : monomers = self . _monomers + self . ligands . _monomers else : monomers = self . _monomers atoms = itertools . chain ( * ( list ( m . get_atoms ( inc_alt_states = inc_alt_states ) ) for m in monomers ) ) return atoms | Flat list of all the Atoms in the Polymer . |
59,869 | def relabel_monomers ( self , labels = None ) : if labels : if len ( self . _monomers ) == len ( labels ) : for monomer , label in zip ( self . _monomers , labels ) : monomer . id = str ( label ) else : error_string = ( 'Number of Monomers ({}) and number of labels ' '({}) must be equal.' ) raise ValueError ( error_str... | Relabels the either in numerically or using a list of labels . |
59,870 | def relabel_atoms ( self , start = 1 ) : counter = start for atom in self . get_atoms ( ) : atom . id = counter counter += 1 return | Relabels all Atoms in numerical order . |
59,871 | def make_pdb ( self , alt_states = False , inc_ligands = True ) : if any ( [ False if x . id else True for x in self . _monomers ] ) : self . relabel_monomers ( ) if self . ligands and inc_ligands : monomers = self . _monomers + self . ligands . _monomers else : monomers = self . _monomers pdb_str = write_pdb ( monomer... | Generates a PDB string for the Polymer . |
59,872 | def rotate ( self , angle , axis , point = None , radians = False ) : q = Quaternion . angle_and_axis ( angle = angle , axis = axis , radians = radians ) self . _vector = q . rotate_vector ( v = self . _vector , point = point ) return | Rotates Atom by angle . |
59,873 | def dict_from_mmcif ( mmcif , path = True ) : if path : with open ( mmcif , 'r' ) as foo : lines = foo . readlines ( ) else : lines = mmcif . splitlines ( ) lines = [ ' ' . join ( x . strip ( ) . split ( ) ) for x in lines ] loop = False cif_data = { } for i , line in enumerate ( lines ) : if not line : continue if lin... | Parse mmcif file into a dictionary . |
59,874 | def get_protein_dict ( cif_data ) : mmcif_data_names = { 'keywords' : '_struct_keywords.text' , 'header' : '_struct_keywords.pdbx_keywords' , 'space_group' : '_symmetry.space_group_name_H-M' , 'experimental_method' : '_exptl.method' , 'crystal_growth' : '_exptl_crystal_grow.pdbx_details' , 'resolution' : '_refine.ls_d_... | Parse cif_data dict for a subset of its data . |
59,875 | def parse_PISCES_output ( pisces_output , path = False ) : pisces_dict = { } if path : pisces_path = Path ( pisces_output ) pisces_content = pisces_path . read_text ( ) . splitlines ( ) [ 1 : ] else : pisces_content = pisces_output . splitlines ( ) [ 1 : ] for line in pisces_content : pdb = line . split ( ) [ 0 ] [ : 4... | Takes the output list of a PISCES cull and returns in a usable dictionary . |
59,876 | def download_decode ( URL , encoding = 'utf-8' , verbose = True ) : if verbose : print ( "Downloading data from " + URL ) req = Request ( URL ) try : with urlopen ( req ) as u : decoded_file = u . read ( ) . decode ( encoding ) except URLError as e : if hasattr ( e , 'reason' ) : print ( 'Server could not be reached.' ... | Downloads data from URL and returns decoded contents . |
59,877 | def olderado_best_model ( pdb_id ) : pdb_code = pdb_id [ : 4 ] . lower ( ) olderado_url = 'http://www.ebi.ac.uk/pdbe/nmr/olderado/searchEntry?pdbCode=' + pdb_code olderado_page = download_decode ( olderado_url , verbose = False ) if olderado_page : parsed_page = BeautifulSoup ( olderado_page , 'html.parser' ) else : re... | Checks the Olderado web server and returns the most representative conformation for PDB NMR structures . |
59,878 | def buff_eval ( params ) : specification , sequence , parsed_ind = params model = specification ( * parsed_ind ) model . build ( ) model . pack_new_sequences ( sequence ) return model . buff_interaction_energy . total_energy | Builds and evaluates BUFF energy of model in parallelization |
59,879 | def buff_internal_eval ( params ) : specification , sequence , parsed_ind = params model = specification ( * parsed_ind ) model . build ( ) model . pack_new_sequences ( sequence ) return model . buff_internal_energy . total_energy | Builds and evaluates BUFF internal energy of a model in parallelization |
59,880 | def rmsd_eval ( rmsd_params ) : specification , sequence , parsed_ind , reference_pdb = rmsd_params model = specification ( * parsed_ind ) model . pack_new_sequences ( sequence ) ca , bb , aa = run_profit ( model . pdb , reference_pdb , path1 = False , path2 = False ) return bb | Builds a model and runs profit against a reference model . |
59,881 | def comparator_eval ( comparator_params ) : top1 , top2 , params1 , params2 , seq1 , seq2 , movements = comparator_params xrot , yrot , zrot , xtrans , ytrans , ztrans = movements obj1 = top1 ( * params1 ) obj2 = top2 ( * params2 ) obj2 . rotate ( xrot , [ 1 , 0 , 0 ] ) obj2 . rotate ( yrot , [ 0 , 1 , 0 ] ) obj2 . rot... | Gets BUFF score for interaction between two AMPAL objects |
59,882 | def parameters ( self , sequence , value_means , value_ranges , arrangement ) : self . _params [ 'sequence' ] = sequence self . _params [ 'value_means' ] = value_means self . _params [ 'value_ranges' ] = value_ranges self . _params [ 'arrangement' ] = arrangement if any ( x <= 0 for x in self . _params [ 'value_ranges'... | Relates the individual to be evolved to the full parameter string . |
59,883 | def make_energy_funnel_data ( self , cores = 1 ) : if not self . parameter_log : raise AttributeError ( 'No parameter log data to make funnel, have you ran the ' 'optimiser?' ) model_cls = self . _params [ 'specification' ] gen_tagged = [ ] for gen , models in enumerate ( self . parameter_log ) : for model in models : ... | Compares models created during the minimisation to the best model . |
59,884 | def funnel_rebuild ( psg_trm_spec ) : param_score_gen , top_result_model , specification = psg_trm_spec params , score , gen = param_score_gen model = specification ( * params ) rmsd = top_result_model . rmsd ( model ) return rmsd , score , gen | Rebuilds a model and compares it to a reference model . |
59,885 | def update_pop ( self ) : candidates = [ ] for ind in self . population : candidates . append ( self . crossover ( ind ) ) self . _params [ 'model_count' ] += len ( candidates ) self . assign_fitnesses ( candidates ) for i in range ( len ( self . population ) ) : if candidates [ i ] . fitness > self . population [ i ] ... | Updates the population according to crossover and fitness criteria . |
59,886 | def initialize_pop ( self ) : self . population = self . toolbox . swarm ( n = self . _params [ 'popsize' ] ) if self . _params [ 'neighbours' ] : for i in range ( len ( self . population ) ) : self . population [ i ] . ident = i self . population [ i ] . neighbours = list ( set ( [ ( i - x ) % len ( self . population ... | Generates initial population with random positions and speeds . |
59,887 | def initialize_pop ( self ) : self . toolbox . register ( "individual" , self . generate ) self . toolbox . register ( "population" , tools . initRepeat , list , self . toolbox . individual ) self . population = self . toolbox . population ( n = self . _params [ 'popsize' ] ) self . assign_fitnesses ( self . population... | Assigns initial fitnesses . |
59,888 | def randomise_proposed_value ( self ) : if self . parameter_type is MMCParameterType . UNIFORM_DIST : ( a , b ) = self . static_dist_or_list self . proposed_value = random . uniform ( a , b ) elif self . parameter_type is MMCParameterType . NORMAL_DIST : ( mu , sigma ) = self . static_dist_or_list self . proposed_value... | Creates a randomly the proposed value . |
59,889 | def accept_proposed_value ( self ) : if self . proposed_value is not None : self . current_value = self . proposed_value self . proposed_value = None return | Changes the current value to the proposed value . |
59,890 | def start_optimisation ( self , rounds , temp = 298.15 ) : self . _generate_initial_model ( ) self . _mmc_loop ( rounds , temp = temp ) return | Begin the optimisation run . |
59,891 | def _generate_initial_model ( self ) : initial_parameters = [ p . current_value for p in self . current_parameters ] try : initial_model = self . specification ( * initial_parameters ) except TypeError : raise TypeError ( 'Failed to build initial model. Make sure that the input ' 'parameters match the number and order ... | Creates the initial model for the optimistation . |
59,892 | def _mmc_loop ( self , rounds , temp = 298.15 , verbose = True ) : current_round = 0 while current_round < rounds : modifiable = list ( filter ( lambda p : p . parameter_type is not MMCParameterType . STATIC_VALUE , self . current_parameters ) ) chosen_parameter = random . choice ( modifiable ) if chosen_parameter . pa... | The main MMC loop . |
59,893 | def _crossover ( self , ind ) : if self . neighbours : a , b , c = random . sample ( [ self . population [ i ] for i in ind . neighbours ] , 3 ) else : a , b , c = random . sample ( self . population , 3 ) y = self . toolbox . clone ( a ) y . ident = ind . ident y . neighbours = ind . neighbours del y . fitness . value... | Used by the evolution process to generate a new individual . |
59,894 | def _generate ( self ) : part = creator . Particle ( [ random . uniform ( - 1 , 1 ) for _ in range ( len ( self . value_means ) ) ] ) part . speed = [ random . uniform ( - self . max_speed , self . max_speed ) for _ in range ( len ( self . value_means ) ) ] part . smin = - self . max_speed part . smax = self . max_spee... | Generates a particle using the creator function . |
59,895 | def update_particle ( self , part , chi = 0.729843788 , c = 2.05 ) : neighbour_pool = [ self . population [ i ] for i in part . neighbours ] best_neighbour = max ( neighbour_pool , key = lambda x : x . best . fitness ) ce1 = ( c * random . uniform ( 0 , 1 ) for _ in range ( len ( part ) ) ) ce2 = ( c * random . uniform... | Constriction factor update particle method . |
59,896 | def _make_individual ( self , paramlist ) : part = creator . Individual ( paramlist ) part . ident = None return part | Makes an individual particle . |
59,897 | def number_of_mmols ( code ) : if mmols_numbers : if code in mmols_numbers . keys ( ) : mmol = mmols_numbers [ code ] [ 0 ] return mmol counter = 1 while True : pdbe_url = "http://www.ebi.ac.uk/pdbe/static/entry/download/{0}-assembly-{1}.cif.gz" . format ( code , counter ) r = requests . get ( pdbe_url ) if r . status_... | Number of . mmol files associated with code in the PDBE . |
59,898 | def get_mmol ( code , mmol_number = None , outfile = None ) : if not mmol_number : try : mmol_number = preferred_mmol ( code = code ) except ( ValueError , TypeError , IOError ) : print ( "No mmols for {0}" . format ( code ) ) return None if mmols_numbers : if code in mmols_numbers . keys ( ) : num_mmols = mmols_number... | Get mmol file from PDBe and return its content as a string . Write to file if outfile given . |
59,899 | def get_mmcif ( code , outfile = None ) : pdbe_url = "http://www.ebi.ac.uk/pdbe/entry-files/download/{0}.cif" . format ( code ) r = requests . get ( pdbe_url ) if r . status_code == 200 : mmcif_string = r . text else : print ( "Could not download mmcif file for {0}" . format ( code ) ) mmcif_string = None if outfile an... | Get mmcif file associated with code from PDBE . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.