mdgo.util module
This module implements utility functions for other modules in the package.
- mdgo.util.atom_vec(atom1, atom2, dimension)[source]
Calculate the vector of the positions from atom2 to atom1.
- Parameters
atom1 (
Atom) – Atom obj 1.atom2 (
Atom) – Atom obj 2.dimension (
ndarray) – box dimension.
- Return type
ndarray- Returns
The obtained vector
- mdgo.util.position_vec(pos1, pos2, dimension)[source]
Calculate the vector from pos2 to pos2.
- Parameters
pos1 (
Union[List[float],ndarray]) – Array of 3d coordinates 1.pos2 (
Union[List[float],ndarray]) – Array of 3d coordinates 2.dimension (
Union[List[float],ndarray]) – box dimension.
- Return type
ndarray- Returns
The obtained vector.
- mdgo.util.angle(a, b, c)[source]
Calculate the angle between three atoms.
- Parameters
a (
ndarray) – Coordinates of atom A.b (
ndarray) – Coordinates of atom B.c (
ndarray) – Coordinates of atom C.
- Return type
floating- Returns
The degree A-B-C.
- mdgo.util.mass_to_name(masses)[source]
Map atom names to element names.
- Parameters
masses (
ndarray) – The masses array of atoms in anUniverse.- Return type
ndarray- Returns
The element name array.
- mdgo.util.lmp_mass_to_name(df)[source]
Create a dict for mapping atom type id to element from the mass information. :type df:
DataFrame:param df: The masses attribute from LammpsData object- Return type
Dict[int,str]- Returns
The element dict.
- Parameters
df (pandas.DataFrame) –
- mdgo.util.assign_name(u, names)[source]
Assign resnames to residues in a MDAnalysis.universe object. The function will not overwrite existing names.
- Parameters
u (
Universe) – The universe object to assign resnames to.names (
ndarray) – The element name array.
- mdgo.util.assign_resname(u, res_dict)[source]
Assign resnames to residues in a MDAnalysis.universe object. The function will not overwrite existing resnames.
- Parameters
u (
Universe) – The universe object to assign resnames to.res_dict (
Dict[str,str]) – A dictionary of resnames, where each resname is a key and the corresponding values are the selection language.
- mdgo.util.res_dict_from_select_dict(u, select_dict)[source]
Infer res_dict (residue selection) from select_dict (atom selection) in a MDAnalysis.universe object.
- Parameters
u (
Universe) – The universe object to assign resnames to.select_dict (
Dict[str,str]) – A dictionary of atom species, where each atom species name is a key and the corresponding values are the selection language.
- Return type
Dict[str,str]- Returns
A dictionary of resnames.
- mdgo.util.res_dict_from_datafile(filename)[source]
Infer res_dict (residue selection) from a LAMMPS data file.
- Parameters
filename (
str) – Path to the data file. The data file must be generated by a CombinedData object.- Return type
Dict[str,str]- Returns
A dictionary of resnames.
- mdgo.util.res_dict_from_lammpsdata(lammps_data)[source]
Infer res_dict (residue selection) from a LAMMPS data file.
- Parameters
lammps_data (
CombinedData) – A CombinedData object.- Return type
Dict[str,str]- Returns
A dictionary of resnames.
- mdgo.util.select_dict_from_resname(u)[source]
Infer select_dict (possibly interested atom species selection) from resnames in a MDAnalysis.universe object. The resname must be pre-assigned already.
- Parameters
u (
Universe) – The universe object to work with.- Return type
Dict[str,str]- Returns
A dictionary of atom species.
- mdgo.util.extract_atom_from_ion(positive, ion, select_dict, number=0)[source]
Assign the most most charged atom and/or one unique atom in the ion into select_dict.
- Parameters
positive (
bool) – Whether the charge of ion is positive. Otherwise negative. Default to True.ion (
Union[Residue,AtomGroup]) – Residue or AtomGroupselect_dict (
Dict[str,str]) – A dictionary of atom species, where each atom species name is a key and the corresponding values are the selection language.number (
int) – The serial number of the ion.
- mdgo.util.extract_atom_from_molecule(resname, molecule, select_dict, number=0)[source]
Assign the most negatively charged atom in the molecule into select_dict
- Parameters
resname (
str) – The name of the moleculemolecule (
Union[Residue,AtomGroup]) – The Residue or AtomGroup obj of the molecule.select_dict (
Dict[str,str]) – A dictionary of atom species, where each atom species name is a key and the corresponding values are the selection language.number (
int) – The serial number of the molecule under the name of resname.
- mdgo.util.ff_parser(ff_dir, xyz_dir)[source]
A parser to convert a force field field from Maestro format to LAMMPS data format.
- Parameters
ff_dir (
str) – The path to the Maestro force field file.xyz_dir (
str) – The path to the xyz structure file.
- Return type
str- Returns
The output LAMMPS data string.
- mdgo.util.concentration_matcher(concentration, salt, solvents, solv_ratio, num_salt=100, mode='v', radii_type='Bondi')[source]
Estimate the number of molecules of each species in a box, given the salt concentration, salt type, solvent molecular weight, solvent density, solvent ratio and total number of salt. TODO: Auto box size according to Debye screening length
- Parameters
concentration (
float) – Salt concentration in mol/L.salt (
Union[float,int,str,Molecule]) –- Four types of input are accepted:
The salt name in string (‘lipf6’ or ‘litfsi’)
Salt molar volume in as a float/int (cm^3/mol)
A pymatgen Molecule object of the salt structure
The path to the salt structure xyz file
Valid names are listed in the MOLAR_VOLUME dictionary at the beginning of this file and currently include only ‘lipf6’ or ‘litfsi’
If a Molecule or structure file is provided, mdgo will estimate the molar volume according to the VdW radii of the atoms. The specific radii used depend on the value of the ‘radii_type’ kwarg (see below).
solvents (
List[Union[str,Dict[str,float]]]) –A list of solvent molecules. A molecule could either be a name (e.g. “water” or “ethylene carbonate”) or a dict containing two keys “mass” and “density” in g/mol and g/mL, respectively.
Valid names are listed in the ALIAS dictionary at the beginning of this file.
solv_ratio (
List[float]) – A list of relative weights or volumes of solvents. Must be the same length as solvents. For example, for a 30% / 70% (w/w) mix of two solvent, pass [0.3, 0.7] or [30, 70]. The sum of weights / volumes does not need to be normalized.num_salt (
int) – The number of salt in the box.mode (
str) – Weight mode (Weight/weight/W/w/W./w.) or volume mode (Volume/volume/V/v/V./v.) for interpreting the ratio of solvents.radii_type (
str) – “Bondi”, “Lange”, or “pymatgen”. Bondi and Lange vdW radii are compiled in this package for H, B, C, N, O, F, Si, P, S, Cl, Br, and I. Choose ‘pymatgen’ to use the vdW radii from pymatgen.Element, which are available for most elements and reflect the latest values in the CRC handbook.
- Return type
Tuple[List,float]- Returns
A list of number of molecules in the simulation box, starting with the salt and followed by each solvent in ‘solvents’. The list is followed by a float of the approximate length of one side of the box in Å.
- mdgo.util.sdf_to_pdb(sdf_file, pdb_file, write_title=True, version=True, credit=True, pubchem=True)[source]
Convert SDF file to PDB file.
- Parameters
sdf_file (
str) – Path to the input sdf file.pdb_file (
str) – Path to the output pdb file.write_title (
bool) – Whether to write title in the pdb file. Default to True.version (
bool) – Whether to version line (remark 4) line in the pdb file. Default to True.credit (
bool) – Whether to credit line (remark 888) in the pdb file. Default to True.pubchem (
bool) – Whether the sdf is downloaded from PubChem. Default to True.