Révision b6f47f2d

b/modules/formats.py
1
"""Module for the conversion of coordinate files to library-workable objects
1
"""Module for the conversion between atomic coordinates files and objects
2 2

  
3 3
functions:
4 4
confs_to_mol_list: Converts the conformers inside a rdkit mol object to a list
5 5
    of separate mol objects.
6 6
rdkit_mol_to_ase_atoms: Converts a rdkit mol object into ase Atoms object.
7
adapt_format: Converts the coordinate files into a required library object type
7
adapt_format: Converts the coordinate files into a required library object type.
8
read_coords: Reads the atomic coordinates resulting from finished calculations.
8 9
"""
9 10

  
10 11
import logging
......
79 80
            ase_atms = ase.io.read(coord_file)
80 81
            atomic_nums = ase_atms.get_atomic_numbers().tolist()
81 82
            xyz_coordinates = ase_atms.positions.tolist()
82
            rd_mol_obj = xyz2mol(atomic_nums, xyz_coordinates, charge=0)  # TODO Charge
83
            # TODO Add routine to read charge
84
            rd_mol_obj = xyz2mol(atomic_nums, xyz_coordinates, charge=0)
83 85
            logger.debug(conv_info)
84 86
            return rd_mol_obj
85 87
        elif filetype(coord_file) == 'mol':
......
90 92
    if requirement == 'ase':
91 93
        logger.debug(conv_info)
92 94
        return ase.io.read(coord_file)
95

  
96

  
97
def read_coords(code, run_type, req):
98
    """Reads the atomic coordinates resulting from finished calculations.
99

  
100
    Given a run_type ('isolated', 'screening' or 'refinement') directory
101
    containing different subdirectories with finished calculations in every
102
    subdirectory, it reads the coordinates inside each subdirectory according to
103
    the specified code and returns a list of objects required.
104

  
105
    @param code: the code that produced the coordinates out of a calculation.
106
    @param run_type: the type of calculation (and also the name of the folder)
107
                     containing the calculation subdirectories.
108
    @param req: The required object type to make the list of.
109
    @return: list of collection-of-atoms objects. (rdkit.Mol, ase.Atoms, etc.)
110
    """
111
    import os
112
    if code == 'cp2k':
113
        pattern = '-pos-1.xyz'
114
    else:
115
        pattern = ''
116
    return [adapt_format(req, f'{run_type}/{conf}/{fil}')
117
            for conf in os.listdir(run_type)
118
            for fil in os.listdir(f"{run_type}/{conf}") if pattern in fil]

Formats disponibles : Unified diff