Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing PATH in files and input options #133

Merged
merged 4 commits into from
Mar 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions aqme/cmin.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@
import time
from aqme.utils import (
load_variables,
substituted_mol,
mol_from_sdf_or_mol_or_mol2,
add_prefix_suffix
add_prefix_suffix,
check_files,
check_xtb
)
from aqme.filter import ewin_filter, pre_E_filter, RMSD_and_E_filter
from aqme.cmin_utils import creation_of_dup_csv_cmin
Expand Down Expand Up @@ -147,10 +148,7 @@ def __init__(self, **kwargs):
os.chdir(self.args.w_dir_main)

# retrieves the different files to run in CMIN
if len(self.args.files) == 0:
self.args.log.write('\nx No files were found! Make sure you use quotation marks if you are using * (i.e. --files "*.sdf")')
self.args.log.finalize()
sys.exit()
_ = check_files(self,'cmin')

# create the dataframe to store the data
self.final_dup_data = creation_of_dup_csv_cmin(self.args.program.lower())
Expand Down Expand Up @@ -277,6 +275,8 @@ def compute_cmin(self, file):
charge,mult,final_mult,dup_data = self.charge_mult_cmin(dup_data, dup_data_idx)

elif self.args.program.lower() == "xtb":
# checks if xTB is installed
_ = self.get_cmin_model()
# sets charge and mult
file_format = os.path.splitext(file)[1]
charge_input, mult_input, final_mult = None, None, None
Expand Down Expand Up @@ -431,7 +431,7 @@ def compute_cmin(self, file):
# xTB AND ANI MAIN OPTIMIZATION PROCESS
def ani_optimize(self, mol, charge, mult):

# Attempts ANI/xTB imports and exits if the programs are not installed
# Attempts ANI imports and exits if the programs are not installed
try:
import torch
import warnings
Expand Down Expand Up @@ -527,15 +527,7 @@ def get_cmin_model(self):
model = getattr(torchani.models,self.args.ani_method)()

elif self.args.program.lower() == "xtb":
try:
subprocess.run(
["xtb", "-h"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
except FileNotFoundError:
self.args.log.write("x xTB is not installed (CREST cannot be used)! You can install the program with 'conda install -c conda-forge xtb'")
self.args.log.finalize()
sys.exit()

_ = check_xtb(self)
model = None

return model
Expand Down
17 changes: 6 additions & 11 deletions aqme/csearch/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,9 @@
from aqme.utils import (
substituted_mol,
load_variables,
set_metal_atomic_number
set_metal_atomic_number,
check_xtb,
get_files
)
from aqme.csearch.crest import xtb_opt_main

Expand Down Expand Up @@ -239,14 +241,7 @@ def __init__(self, **kwargs):
self.args.auto_metal_atoms = False

if self.args.program.lower() == "crest":
try:
subprocess.run(
["xtb", "-h"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
)
except FileNotFoundError:
self.args.log.write("x xTB is not installed (CREST cannot be used)! You can install the program with 'conda install -c conda-forge xtb'")
self.args.log.finalize()
sys.exit()
_ = check_xtb(self)

if self.args.smi is None and self.args.input == "":
self.args.log.write("\nx Program requires either a SMILES or an input file to proceed! Please look up acceptable file formats. Specify: smi='CCC' (or input='filename.csv')")
Expand All @@ -271,7 +266,7 @@ def __init__(self, **kwargs):
if self.args.smi is not None:
csearch_files = [self.args.name]
else:
csearch_files = glob.glob(self.args.input)
csearch_files = get_files(self.args.input)
if len(csearch_files) == 0:
self.args.log.write(f"\nx Input file ({self.args.input}) not found!")
self.args.log.finalize()
Expand All @@ -292,7 +287,7 @@ def __init__(self, **kwargs):

# store all the information into a CSV file
csearch_file_no_path = (
csearch_file.replace("/", "\\").split("\\")[-1].split(".")[0]
os.path.basename(csearch_file).split(".")[0]
)
self.csearch_csv_file = self.args.w_dir_main.joinpath(
f"CSEARCH-Data-{csearch_file_no_path}.csv"
Expand Down
39 changes: 26 additions & 13 deletions aqme/csearch/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def prepare_cdx_files(args, csearch_file):

job_inputs = []
for i, (smiles, _) in enumerate(molecules):
name = f"{csearch_file.split('.')[0]}_{str(i)}"
name = f"{os.path.basename(csearch_file).split('.')[0]}_{str(i)}"
name = add_prefix_suffix(name, args)

obj = (
Expand Down Expand Up @@ -294,19 +294,22 @@ def generate_mol_from_cdx(csearch_file):
def prepare_com_files(args, csearch_file):
job_inputs = []

if csearch_file.split(".")[1] in ["gjf", "com"]:
filename = os.path.basename(csearch_file)
if filename.split('.')[1] in ["gjf", "com"]:
xyz_file, _, _ = com_2_xyz(csearch_file)
_, charge, mult = get_info_input(csearch_file)
else:
xyz_file = csearch_file
charge, mult = read_xyz_charge_mult(xyz_file)
xyz_2_sdf(xyz_file)
name = os.path.splitext(csearch_file)[0]
name = add_prefix_suffix(name, args)
_ = xyz_2_sdf(xyz_file)

sdffile = f'{os.path.dirname(csearch_file)}/{filename.split(".")[0]}.sdf'

sdffile = f"{os.path.splitext(csearch_file)[0]}.sdf"
suppl, _, _, _ = mol_from_sdf_or_mol_or_mol2(sdffile, "csearch")

name = filename.split('.')[0]
name = add_prefix_suffix(name, args)

obj = (
suppl[0],
name,
Expand All @@ -318,28 +321,37 @@ def prepare_com_files(args, csearch_file):
args.constraints_dihedral,
)
job_inputs.append(obj)
if os.path.basename(csearch_file).split('.')[1] in ["gjf", "com"]:
os.remove(xyz_file)
os.remove(sdffile)

return job_inputs


def prepare_pdb_files(args, csearch_file):
filename = os.path.basename(csearch_file)
sdffile = f'{os.path.dirname(csearch_file)}/{filename.split(".")[0]}.sdf'
command_pdb = [
"obabel",
"-ipdb",
csearch_file,
"-osdf",
f'-O{csearch_file.split(".")[0]}.sdf',
f'-O{sdffile}',
]
subprocess.run(command_pdb, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
job_inputs = prepare_sdf_files(args, csearch_file)
os.remove(f'{csearch_file.split(".")[0]}.sdf')
os.remove(sdffile)
return job_inputs


def prepare_sdf_files(args, csearch_file):
suppl, charges, mults, IDs = mol_from_sdf_or_mol_or_mol2(csearch_file, "csearch")
job_inputs = []
filename = os.path.basename(csearch_file)
sdffile = f'{os.path.dirname(csearch_file)}/{filename}'
suppl, charges, mults, IDs = mol_from_sdf_or_mol_or_mol2(sdffile, "csearch")
if sdffile.split('.')[0] in ['mol','mol2']:
os.remove(f'{sdffile.split(".")[0]}.sdf')

job_inputs = []
for mol, charge, mult, name in zip(suppl, charges, mults, IDs):
name = add_prefix_suffix(name, args)
obj = (
Expand Down Expand Up @@ -391,15 +403,16 @@ def com_2_xyz(input_file):
COM to XYZ to SDF for obabel
"""

filename = input_file.split(".")[0]
filename = os.path.basename(input_file).split('.')[0]
path_xyz = f'{os.path.dirname(input_file)}/{filename}.xyz'

# Create the 'xyz' file and/or get the total charge
xyz, charge, mult = get_info_input(input_file)
xyz_txt = "\n".join(xyz)
with open(f"{filename}.xyz", "w") as F:
with open(path_xyz, "w") as F:
F.write(f"{len(xyz)}\n{filename}\n{xyz_txt}\n")

return f"{filename}.xyz", charge, mult
return path_xyz, charge, mult


def minimize_rdkit_energy(mol, conf, log, FF, maxsteps):
Expand Down
9 changes: 4 additions & 5 deletions aqme/qcorr.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
load_variables,
read_file,
cclib_atoms_coords,
check_files
)
from aqme.qcorr_utils import (
detect_linear,
Expand All @@ -108,13 +109,11 @@ def __init__(self, **kwargs):
# load default and user-specified variables
self.args = load_variables(kwargs, "qcorr")

if len(self.args.files) == 0:
self.args.log.write('\nx No files were found! Make sure you use quotation marks if you are using * (i.e. --files "*.log")')
self.args.log.finalize()
sys.exit()
# retrieves the different files to run in QCORR
_ = check_files(self,'qcorr')

# QCORR analysis
if self.args.files[0].split('.')[1].lower() not in ['log','out','json']:
if os.path.basename(self.args.files[0]).split('.')[1].lower() not in ['log','out','json']:
self.args.log.write(f"\nx The format used ({self.args.files[0].split('.')[1].lower()}) is not compatible with QCORR! Formats accepted: log, out, json")
self.args.log.finalize()
sys.exit()
Expand Down
9 changes: 4 additions & 5 deletions aqme/qdescp.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@
load_variables,
read_xyz_charge_mult,
mol_from_sdf_or_mol_or_mol2,
run_command
run_command,
check_files
)
from aqme.qdescp_utils import (
get_boltz_avg_properties_xtb,
Expand Down Expand Up @@ -116,10 +117,8 @@ def __init__(self, **kwargs):
else:
destination = Path(self.args.destination)

if len(self.args.files) == 0:
self.args.log.write('\nx No files were found! Make sure you use quotation marks if you are using * (i.e. --files "*.sdf")')
self.args.log.finalize()
sys.exit()
# retrieves the different files to run in QDESCP
_ = check_files(self,'qdescp')

qdescp_program = True
if self.args.program is None:
Expand Down
7 changes: 3 additions & 4 deletions aqme/qprep.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
read_xyz_charge_mult,
mol_from_sdf_or_mol_or_mol2,
add_prefix_suffix,
check_files
)
from aqme.csearch.crest import xyzall_2_xyz
from pathlib import Path
Expand All @@ -77,10 +78,8 @@ def __init__(self, create_dat=True, **kwargs):
# load default and user-specified variables
self.args = load_variables(kwargs, "qprep", create_dat=create_dat)

if len(self.args.files) == 0:
self.args.log.write('\nx No files were found! Make sure you use quotation marks if you are using * (i.e. --files "*.sdf")')
self.args.log.finalize()
sys.exit()
# retrieves the different files to run in QPREP
_ = check_files(self,'qprep')

file_format = os.path.splitext(self.args.files[0])[1].split('.')[1]
if file_format.lower() not in ['sdf', 'xyz', 'pdb', 'log', 'out', 'json']:
Expand Down
Loading