schrodinger.application.glide.csv_utils module¶
Utility functions used for reading and writing CSV files in Glide. For example, figuring out which column should be written (get_csv_props()) or accessing properties which came from CSV files from Structures, after accounting for various naming conventions (get_prop()).
- class schrodinger.application.glide.csv_utils.RawCsvWriter(filename: str, append: bool = False, fields: Optional[list[str]] = None)¶
Bases:
AbstractContextManager
,Appendable
,Extendable
Writes a raw Glide output CSV file. Based on the config provided, it will determine the appropriate header and fields to include.
The
finalize_csv
free function can be used to transform the output of this writer into the the final output. Finalization will alter the file extension and compress, if necessary.- __init__(filename: str, append: bool = False, fields: Optional[list[str]] = None)¶
- Parameters:
filename – raw CSV file name. Conventionally, these use the “.rawcsv” extension
append – whether to open the file in append mode
fields – which Structure properties to write to the CSV file, in additions to those in
BASE_CSV_FIELDS
.
- append(st)¶
- extend(sts)¶
- schrodinger.application.glide.csv_utils.finalize_csv(final_filename: str, leave_empty_raw_file: bool = False)¶
Renames and optionally compresses raw CSV file, then removes the original file. Note that this method should be called after the context is exited. We compress after the file is written because we want to flush after each row is written, which is incompatible with writing a gzipped file.
- Parameters:
final_filename – final name of the CSV file. The raw filename will be derived from it.
leave_empty_raw_file – whether to leave an empty raw file instead of deleting it. (We would like to delete the raw file from the launch directory, but since that’s not supported by job control, the best we can do is send back an empty file to overwrite it.)
- schrodinger.application.glide.csv_utils.get_csv_header(ligand_files)¶
Return the header row if the ligands come from CSV file(s). Raises a GlideError if different files have different headers.
- Returns:
first line on the file, including EOL
- Return type:
str
- schrodinger.application.glide.csv_utils.parse_csv_line(line)¶
- schrodinger.application.glide.csv_utils.write_csv_record_to_string(record)¶
- schrodinger.application.glide.csv_utils.get_csv_props(glide_job, ligfile_fields=None)¶
Return the list of the names of properties that should be stored in the properties table, based on the value of CSV_PROPS_FILE, if present, or else the default CSV config file. Optionally, additional fields may be specified and will be appended to the list unless they are already being written by default.
- Parameters:
glide_job (glide_input.GlideJob) – Glide job object (dict of SIF keyword-value pairs)
ligfile_fields (Optional[list[str]]) – The fields found in the input CSV file(s).
- Returns:
A list of CSV properties.
- Return type:
list[str]
- schrodinger.application.glide.csv_utils.parse_csv_props_file(filename, precision)¶
Parse the CSV props config file. This is the file specified by the CSV_PROPS_FILE keyword.
- Parameters:
precision (str) – SP, XP, or WScore
- Returns:
A list of CSV properties
- Return type:
list[str]
- schrodinger.application.glide.csv_utils.get_prop(st, prop)¶
Retrieve the property from a structure, even if the name is mangled by an upstream process. Is able to access properties based on their original name in a CSV header, even if the structure has been processed by the mmshare CSV reader or Ligprep.
- Parameters:
st (structure.Structure) – The structure.
prop (str) – The property name.
- Returns:
The property, if found. Otherwise an empty string.
- schrodinger.application.glide.csv_utils.get_props(st, props)¶
Return a list with the values of all the Structure properties listed in props. If a property is not preset, this will try several variants of the property name by adding prefixes that are used by the mmshare CSV reader and Ligprep.
- schrodinger.application.glide.csv_utils.format_row(row, precision=4)¶
Format the numeric values in a CSV row to a fixed precision.
- schrodinger.application.glide.csv_utils.get_ligfile_fields(config) list[str] ¶
Get a list of fields from the input CSV file(s), if required for the job.
If the job does not use CSV input or is not configuired to use the input headers, return empty.
- Parameters:
config – Glide Config object, used to determine whether and where from to get the fields
- Raise:
GlideError: if the input CSV file(s) have invalid or inconsistent headers.