Statistiques
| Branche: | Tag: | Révision :

dockonsurf / modules / read_coords.py @ 8ab593ee

Historique | Voir | Annoter | Télécharger (1000 octet)

1
def read_coords(requirement, coord_file):
2
    from ase.io.formats import filetype
3

    
4
    req_vals = ['rdkit', 'ase']
5
    file_type_vals = ['xyz', 'mol']
6
    assert requirement in req_vals, ValueError('Not an adequate requirement.\n'
7
                                    f'adequate requirements: {req_vals}')
8
    assert filetype(coord_file) in file_type_vals, TypeError('The file formnat '
9
                                                             'is not supported')
10

    
11
    if requirement == 'rdkit':
12
        if filetype(coord_file) == 'xyz':
13
            from xyz2mol import xyz2mol, read_xyz_file
14
            atoms, charge, xyz_coordinates = read_xyz_file(coord_file)
15
            rd_mol_obj = xyz2mol(atoms, xyz_coordinates, charge=charge)
16
            return rd_mol_obj
17
        elif filetype(coord_file) == 'mol':
18
            from rdkit.Chem import MolFromMolFile
19
            return MolFromMolFile(coord_file)
20

    
21
    if requirement == 'ase':
22
        import ase.io
23
        return ase.io.read(coord_file)