|
| 1 | +""" |
| 2 | +This module enhances the COSMO-SAC package with the `DirectImport` feature, |
| 3 | +providing a more flexible and organized method for managing sigma profiles. |
| 4 | +Unlike the standard import method requiring sigma profiles in a single folder, |
| 5 | +`DirectImport` allows for storing profiles in separate directories and specifying |
| 6 | +the path and name of the sigma file for each component. This approach facilitates |
| 7 | +enhanced organization and flexible testing of different sigma profiles for the |
| 8 | +same component. |
| 9 | +
|
| 10 | +Author: Ivan Antolovic |
| 11 | +E-Mail: ivan.antolovic@tu-berlin.de |
| 12 | +
|
| 13 | +Note: The `DirectImport` method originated during the work on the paper: |
| 14 | +https://pubs.acs.org/doi/10.1021/acs.molpharmaceut.4c00342 |
| 15 | +Example profiles are taken from: https://github.com/ivanantolo/cosmopharm |
| 16 | +""" |
| 17 | + |
| 18 | +import cCOSMO |
| 19 | +from pathlib import Path |
| 20 | + |
| 21 | +# Get the directory where the script is located |
| 22 | +script_dir = Path(__file__).resolve().parent |
| 23 | + |
| 24 | +# Constants |
| 25 | +PROFILES_API = script_dir / "profiles/pharmaceuticals" |
| 26 | +PROFILES_POLY = script_dir / "profiles/polymers" |
| 27 | +PATH_TO_SIGMAS = script_dir / "profiles/sigma3" |
| 28 | +PATH_TO_COMPLIST = script_dir / "profiles/complist.txt" |
| 29 | +PATH_TO_PROFILES = [PROFILES_API, PROFILES_POLY] |
| 30 | + |
| 31 | +def import_delaware(names, path_to_sigmas, path_to_complist): |
| 32 | + """ |
| 33 | + Imports sigma profiles using the DelawareProfileDatabase. |
| 34 | +
|
| 35 | + Parameters: |
| 36 | + - names: A list of component names. |
| 37 | + - path_to_sigmas: The file path to the sigma profiles. |
| 38 | + - path_to_complist: The file path to the component list. |
| 39 | +
|
| 40 | + Returns: |
| 41 | + A tuple containing the COSMO3 object and the database object. |
| 42 | +
|
| 43 | + Considerations: |
| 44 | + - All sigma profiles must be located in the same directory. |
| 45 | + - All sigma profiles must be listed in complist.txt. |
| 46 | + - Using .xlsx files for adding new profiles and converting them to .txt is recommended. |
| 47 | + - Much of the information in complist.txt is not necessary for importing sigma profiles. |
| 48 | + - Names used in complist.txt do not correspond to unique identifiers. |
| 49 | + - One name corresponds to one identifier, which poses a challenge when dealing with modifications. |
| 50 | + - The same name may be associated with different .sigma files. |
| 51 | + """ |
| 52 | + db = cCOSMO.DelawareProfileDatabase(str(path_to_complist), str(path_to_sigmas)) |
| 53 | + for name in names: |
| 54 | + db.add_profile(name) |
| 55 | + return cCOSMO.COSMO3(names, db), db |
| 56 | + |
| 57 | +def import_direct(names, paths): |
| 58 | + """ |
| 59 | + Directly imports sigma profiles using DirectImport. |
| 60 | +
|
| 61 | + Parameters: |
| 62 | + - names: A list of component names. |
| 63 | + - paths: A list of paths to the sigma profiles. |
| 64 | +
|
| 65 | + Returns: |
| 66 | + A tuple containing the COSMO3 object and the database object. |
| 67 | +
|
| 68 | + Advantages: |
| 69 | + - Profiles can be stored in separate directories. |
| 70 | + - No need for a .txt file listing all profiles. |
| 71 | + - Provides flexibility for testing different sigma profiles for the same component. |
| 72 | + - Enhances the organization of profiles. |
| 73 | + """ |
| 74 | + db = cCOSMO.DirectImport() |
| 75 | + for name, path in zip(names, paths): |
| 76 | + db.add_profile(name, str(path)) |
| 77 | + return cCOSMO.COSMO3(names, db), db |
| 78 | + |
| 79 | +def display_profile(db, name): |
| 80 | + """ |
| 81 | + Displays information about a single profile from the database object. |
| 82 | +
|
| 83 | + Parameters: |
| 84 | + - db: The database object containing the profiles. |
| 85 | + - name: The name for the profile to display. |
| 86 | + """ |
| 87 | + try: |
| 88 | + profile = db.get_profile(name) |
| 89 | + print(f"Name: {profile.name}") |
| 90 | + print(f"Surface Area (A^2): {profile.A_COSMO_A2}") |
| 91 | + print(f"Volume (A^3): {profile.V_COSMO_A3}") |
| 92 | + # print(f"Sigma Profile (non-hydrogen-bonding segments, first 5 elements): {profile.profiles.nhb.sigma[:5]}") |
| 93 | + # print(f"Probability (non-hydrogen-bonding segments, first 5 elements): {profile.profiles.nhb.psigmaA[:5]}") |
| 94 | + except Exception as e: |
| 95 | + print(f"Error retrieving profile for {name}: {e}") |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + names = ['SIM', 'PLGA50'] |
| 99 | + |
| 100 | + # Import profiles using both methods |
| 101 | + cosmo_delaware, db_delaware = import_delaware(names, PATH_TO_SIGMAS, PATH_TO_COMPLIST) |
| 102 | + cosmo_direct, db_direct = import_direct(names=names, paths=PATH_TO_PROFILES) |
| 103 | + |
| 104 | + # Display information about the imported profiles |
| 105 | + print("\nProfiles imported using DelawareProfileDatabase:") |
| 106 | + for name in names: |
| 107 | + display_profile(db_delaware, name) |
| 108 | + |
| 109 | + print("\nProfiles imported using DirectImport:") |
| 110 | + for name in names: |
| 111 | + display_profile(db_direct, name) |
0 commit comments