将简单数据格式文件(.sdf)转换为csv

问题描述 投票:0回答:1

有谁知道如何将简单数据格式文件(扩展名.sdf)转换为csv?欲了解更多信息:
https://pdfs.semanticscholar.org/b1f8/5aa762d9178a98179c5590cd9d541f8149ac.pdf

您还可以检查以下链接:http://solarmuri.ssl.berkeley.edu/~fisher/public/software/SDF

我进行了广泛的搜索,但没有太多信息可以帮助我解决这个问题。

简单数据格式 (SDF) 是一种独立于平台、保留精度的二进制数据 I/O 格式,能够处理大型多维数组。它由加州大学伯克利分校空间科学实验室研究员 George H. Fisher 于 2007 年编写,并根据 GNU 通用公共许可证发布。

如果有人使用过此文件并可以给我提供意见。谢谢你:-)

binaryfiles file-conversion sdf
1个回答
0
投票
from rdkit import Chem
from rdkit.Chem import PandasTools

def sdf_to_csv(sdf_file, output_file, delimiter=','):
    """
    Convert an SDF file to a CSV or TSV file.
    
    Args:
        sdf_file (str): Path to the input SDF file.
        output_file (str): Path to the output CSV or TSV file.
        delimiter (str, optional): Delimiter to use in the output file. Default is ',' (CSV).
    """
    # Read the SDF file
    suppl = Chem.SDMolSupplier(sdf_file)

    # Convert to a pandas DataFrame
    df = PandasTools.LoadSDF(sdf_file, smilesName='SMILES', molColName='Molecule', includeFingerprints=False)

    # Drop the 'Molecule' column if present
    if 'Molecule' in df.columns:
        df = df.drop('Molecule', axis=1)

    # Save the DataFrame as CSV or TSV
    df.to_csv(output_file, sep=delimiter, index=False)
    
    print(f"Conversion complete! Output file: {output_file}")

# Example usage
sdf_file = 'input.sdf'  # Replace with the actual path to your SDF file
csv_file = 'output.csv'

sdf_to_csv(sdf_file, csv_file)`
© www.soinside.com 2019 - 2024. All rights reserved.