pysoftk.format_printers package
Submodules
pysoftk.format_printers.format_mol module
- class pysoftk.format_printers.format_mol.Cnv(file_mol)[source]
Bases:
objectA class for converting molecular files from one format to another using OpenBabel.
This class provides a utility to convert a molecule stored in a file of a given format (e.g., PDB, SDF, MOL2) to a different specified format.
- Returns:
file – A new file containing the provided molecule in the chosen output format.
- Return type:
str
- file_in_out(fmt='mol2')[source]
Converts a molecular file from its current format to a specified output format.
This function leverages OpenBabel to perform the file conversion. It automatically detects the input file format from its extension and converts it to the format specified by the fmt parameter.
- Parameters:
fmt (str, optional) – The desired output format for the converted file (e.g., “pdb”, “xyz”, “sdf”). Defaults to “mol2”.
- Returns:
This function does not return any value. It creates a new file in the same directory as the input file, with the converted format and the original filename (before its extension) appended with the new format’s extension.
- Return type:
None
- class pysoftk.format_printers.format_mol.Fmt(mol)[source]
Bases:
objectA class designed for printing RDKit Mol objects into various molecular file formats.
This class provides methods to convert an RDKit Mol object into common chemical file formats such as XYZ, PDB, and MOL, as well as a more general format conversion.
- Returns:
file – A file containing the provided molecule in the chosen format.
- Return type:
str
- format_print(output_name)[source]
Prints the molecule into a user-provided file format.
This function attempts to convert and write the molecule to a file based on the extension provided in output_name. It handles both RDKit Mol objects and Pybel Molecule objects. If an RDKit Mol is provided, it’s first converted to a PDB block and then read by Pybel to facilitate writing to the desired format.
- Parameters:
output_name (str) – The desired name for the output file, including the file extension (e.g., “molecule.mol2”, “compound.smi”). The extension determines the output format.
- Raises:
TypeError – If the input mol is neither an RDKit Mol object nor a Pybel Molecule object, indicating an invalid molecule type.
- mol_print(output_name)[source]
Prints the molecule to a MOL file format.
This method handles both RDKit Mol objects and Pybel Molecule objects. For RDKit Mol objects, it utilizes Chem.MolToMolFile. For Pybel Molecule objects, it ensures bond orders are perceived and hydrogens are added before writing the file.
- Parameters:
output_name (str) – The desired name for the output MOL file.
- Raises:
TypeError – If the input mol is neither an RDKit Mol object nor a Pybel Molecule object, indicating an invalid molecule type.
- pdb_print(output_name)[source]
Prints the molecule to a PDB file format.
This method supports both RDKit Mol objects and Pybel Molecule objects. For RDKit Mol objects, it uses Chem.MolToPDBFile. For Pybel Molecule objects, it ensures bond orders are perceived and hydrogens are added before writing the file.
- Parameters:
output_name (str) – The desired name for the output PDB file.
- Raises:
TypeError – If the input mol is neither an RDKit Mol object nor a Pybel Molecule object, indicating an invalid molecule type.
- xyz_print(output_name)[source]
Prints the molecule to an XYZ file format.
This method handles both RDKit Mol objects and Pybel Molecule objects. For RDKit Mol objects, it uses Chem.MolToXYZFile. For Pybel Molecule objects, it ensures bond orders are perceived and hydrogens are added before writing the file.
- Parameters:
output_name (str) – The desired name for the output XYZ file.
- Raises:
TypeError – If the input mol is neither an RDKit Mol object nor a Pybel Molecule object, indicating an invalid molecule type.