S SmartDocs
Series: AI for Chemistry python 30 lines · Updated 2024-06-27

volume.py

AI for Chemistry/code/2025_COSMO/data/s-profiles-all/area_volume-org/volume.py

import pandas as pd
import numpy as np
import csv
import glob


csv_list = glob.glob(r"D:\COSMOSAC-master\COSMO\COSMO_all\s-profiles-all\s-profile-area\*.csv")
# csv_list = glob.glob(r"C:\Users\user\Desktop\COSMOSAC-master\COSMO\COSMO_all\s-profiles-all\s-profile\*.csv")

print("共有%s個CSV檔"% len(csv_list))
print(csv_list)

# with open("s-profile-area_volume.csv", 'w', newline='') as file:
with open("s-profile_volume.csv", 'w', newline='') as file:
    new_writer = csv.writer(file)
    new_writer.writerow(["COSMO","volume"])
    for i in csv_list:
        if "-b3lyp.csv"==i[-10:]:                                #最後10個字相等(-b3lyp.csv)
            csvreader = csv.reader(open(i, "r"))
            for index, rows in enumerate(csvreader):
                if index == 52:                                  #index == 52 (第53行)
                    ni="".join([a for a in i[-25:-14] if a.isdigit()])    # 取各檔名(COSMO)最後面數過來第22個(最多)~最後面數過來第14個(至少) (54676228-opt-b3lyp.csv)
                    fileHeader = [ni, rows[1]]                            # 則取54676228
                    new_writer.writerow(fileHeader)
file.close()





Related articles