Example #1
0
 def read_n_files( filenames ) :
     """                                                   
     `filenames' is a list of file names. Reads the files and deposits them into the `KBASE'. Returns a list of keys.                                                           
     """                                                   
     strucid = []
     for fn in filenames :
         strucs = read_file( fn )
         for e in strucs:                                  
             id = KBASE.deposit( e.id(), e )               
             KBASE.deposit_extra(id, "filename", (fn))
             e.set_id( id )                                
             strucid.append( id )                          
     return strucid
Example #2
0
 def read_n_files( filenames ) :
     """
     `filenames' is a list of file names. The format of each file will be determined from the file's extension name. Reads
     the files and deposits them into the `KBASE'. Returns a list of keys.
     """
     strucid = []
     for fn in filenames :
         strucs = read_file( fn )
         for e in strucs :
             id = KBASE.deposit( e.id(), e )
             KBASE.deposit_extra(id, "filename", (fn))
             e.set_id( id )
             strucid.append( id )
     return strucid
Example #3
0
    def deposit_to_kbase(id0, id1, atom_match0, atom_match1):
        """
        Deposits a MCS substructure and relevant information into the kbase and returns its ID in the C{KBASE}.

        @type         id0: C{str}
        @param        id0: ID of the first (reference) molecule in the C{KBASE}
        @type         id1: C{str}
        @param        id1: ID of the second molecule in the C{KBASE}
        @type  atom_match: C{list} of C{int}
        @param atom_match: A list of atom indices of matches atoms in the reference molecule
        @type     mcs_mol: C{Struc}
        @param    mcs_mol: C{Struc} object of the MCS substructure        
        """
        mol0 = KBASE.ask(id0)
        mol1 = KBASE.ask(id1)
        name0 = mol0.title()
        name1 = mol1.title()
        mcs_title = "mcs@%s..%s" % (
            name0,
            name1,
        )
        mcs_id = hashlib.sha1(mcs_title).hexdigest()
        mcs_id = KBASE.deposit(mcs_id, mcs_title)

        # Sorts the two lists according to the ascending order of atom indices of the first list.
        atom_match0, atom_match1 = zip(*sorted(zip(atom_match0, atom_match1),
                                               cmp=lambda x, y: x[0] - y[0]))
        atom_match0, atom_match1 = list(atom_match0), list(atom_match1)

        KBASE.deposit_extra(mcs_id, "mcs-parents", (
            id0,
            id1,
        ))
        KBASE.deposit_extra(mcs_id, "mcs-matches", {
            id0: atom_match0,
            id1: atom_match1,
        })

        return mcs_id