dockonsurf / modules / read_coords.py @ 8ab593ee
Historique | Voir | Annoter | Télécharger (1000 octet)
1 | 8ab593ee | Carles | def read_coords(requirement, coord_file): |
---|---|---|---|
2 | 8ab593ee | Carles | from ase.io.formats import filetype |
3 | 8ab593ee | Carles | |
4 | 8ab593ee | Carles | req_vals = ['rdkit', 'ase'] |
5 | 8ab593ee | Carles | file_type_vals = ['xyz', 'mol'] |
6 | 8ab593ee | Carles | assert requirement in req_vals, ValueError('Not an adequate requirement.\n' |
7 | 8ab593ee | Carles | f'adequate requirements: {req_vals}')
|
8 | 8ab593ee | Carles | assert filetype(coord_file) in file_type_vals, TypeError('The file formnat ' |
9 | 8ab593ee | Carles | 'is not supported')
|
10 | 8ab593ee | Carles | |
11 | 8ab593ee | Carles | if requirement == 'rdkit': |
12 | 8ab593ee | Carles | if filetype(coord_file) == 'xyz': |
13 | 8ab593ee | Carles | from xyz2mol import xyz2mol, read_xyz_file |
14 | 8ab593ee | Carles | atoms, charge, xyz_coordinates = read_xyz_file(coord_file) |
15 | 8ab593ee | Carles | rd_mol_obj = xyz2mol(atoms, xyz_coordinates, charge=charge) |
16 | 8ab593ee | Carles | return rd_mol_obj
|
17 | 8ab593ee | Carles | elif filetype(coord_file) == 'mol': |
18 | 8ab593ee | Carles | from rdkit.Chem import MolFromMolFile |
19 | 8ab593ee | Carles | return MolFromMolFile(coord_file)
|
20 | 8ab593ee | Carles | |
21 | 8ab593ee | Carles | if requirement == 'ase': |
22 | 8ab593ee | Carles | import ase.io |
23 | 8ab593ee | Carles | return ase.io.read(coord_file) |