Utils#

Helper functions for the package.

nbed.utils.build_ordered_xyz_string(struct_dict: dict, active_atom_inds: list) str[source]#

Get raw xyz string of molecular geometry.

This function orders the atoms in struct_dict according to the ordering given in atom_ordering_by_inds list.

Parameters:
  • struct_dict (dict) – Dictionary of indexed atoms and Cartesian coordinates (x,y,z)

  • active_atom_inds (list) – list of indices to be considered active. This will put these atoms to the top of the xyz file. Note indices are chosen from the struct_dict.

Returns:

raw xyz string of molecular geometry (atoms ordered by atom_ordering_by_inds list)

Return type:

xyz_string (str)

Example

input_struct_dict = { 0: (‘O’, (0, 0, 0)),

1: (‘H’, (0.2774, 0.8929, 0.2544)), 2: (‘H’, (0.6068, -0.2383, -0.7169))

}

xyz_string = ordered_xyz_string(‘water’, input_struct_dict, [1,0,2]) print(xyz_string)

>> 3

H 0.2774 0.8929 0.2544 O 0 0 0 H 0.6068 -0.2383 -0.7169

nbed.utils.parse() NbedConfig[source]#

Parse arguments from command line interface.

nbed.utils.pubchem_mol_geometry(molecule_name) dict[source]#

Wrapper of Openfermion function to extract geometry using the molecule’s name from the PubChem.

Returns a dictionary of atomic type and xyz location, each indexed by dictionary key.

Parameters:

molecule_name (str) – Name of molecule to search on pubchem

Returns:

Keys index atoms and values contain Tuple of (‘atom_id’, (x_loc, y_loc, z_loc)

Return type:

struct_dict (dict)

Example: output = pubchem_mol_geometry(‘H2O’) print(output)

>> { 0: (‘O’, (0, 0, 0)),

1: (‘H’, (0.2774, 0.8929, 0.2544)), 2: (‘H’, (0.6068, -0.2383, -0.7169)) }

nbed.utils.save_ordered_xyz_file(file_name: str, struct_dict: dict, active_atom_inds: list, save_location: Path | None = None) Path[source]#

Saves .xyz file in a molecular_structures directory.

This function orders the atoms in struct_dict according to the ordering given in atom_ordering_by_inds list. The file is then saved. The location of this director is either at save_location, or if not defined then in current working dir. Function returns the path to xyz file.

Parameters:
  • file_name (str) – Name of xyz file

  • struct_dict (dict) – Dictionary of indexed atoms and Cartesian coordinates (x,y,z)

  • active_atom_inds (list) – list of indices to be considered active. This will put these atoms to the top of the xyz file. Note indices are chosen from the struct_dict.

  • save_location (Path) – Path of where to save xyz file. If not defined then current working dir used.

Returns:

Path to xyz file

Return type:

xyz_file_path (Path)

Example: input_struct_dict = { 0: (‘O’, (0, 0, 0)),

1: (‘H’, (0.2774, 0.8929, 0.2544)), 2: (‘H’, (0.6068, -0.2383, -0.7169))

}

path = save_ordered_xyz_file(‘water’, input_struct_dict, [1,0,2]) print(path) >> ../molecular_structures/water.xyz

with open(path,’r’) as infile:

xyz_string = infile.read()

print(xyz_string)

>> 3

H 0.2774 0.8929 0.2544 O 0 0 0 H 0.6068 -0.2383 -0.7169

nbed.utils.setup_logs() None[source]#

Initialise logging.