@@ -380,7 +380,7 @@ def charge(self, property_map={}, is_lambda1=False):
380380 own naming scheme, e.g. { "charge" : "my-charge" }
381381
382382 is_lambda1 : bool
383- Whether to use the charge at lambda = 1 if the molecule is merged .
383+ Whether to use the charge at lambda = 1 for perturbable molecules .
384384
385385 Returns
386386 -------
@@ -1158,6 +1158,117 @@ def nPerturbableMolecules(self):
11581158 """
11591159 return len (self .getPerturbableMolecules ())
11601160
1161+ def getCoordinates (self , is_lambda1 = False , property_map = {}):
1162+ """
1163+ Return the coordinates of all atoms in the system as a NumPy array.
1164+ Coordinates are returned in Angstroms.
1165+
1166+ Parameters
1167+ ----------
1168+
1169+ is_lambda1 : bool
1170+ Whether to use the coordinates at lambda = 1 for perturbable molecules.
1171+
1172+ property_map : dict
1173+ A dictionary that maps system "properties" to their user defined
1174+ values. This allows the user to refer to properties with their
1175+ own naming scheme, e.g. { "charge" : "my-charge" }
1176+
1177+ Returns
1178+ -------
1179+
1180+ coordinates : numpy.ndarray
1181+ The coordinates of all atoms in the system in Angstroms.
1182+ """
1183+
1184+ if not isinstance (is_lambda1 , bool ):
1185+ raise TypeError ("'is_lambda1' must be of type 'bool'" )
1186+
1187+ if not isinstance (property_map , dict ):
1188+ raise TypeError ("'property_map' must be of type 'dict'" )
1189+
1190+ import sire as _sr
1191+
1192+ # Convert to a new Sire system.
1193+ mols = _sr .system .System (self ._sire_object )
1194+
1195+ # Link to the correct end-state if required.
1196+ if self .nPerturbableMolecules () > 0 :
1197+ if is_lambda1 :
1198+ mols = _sr .morph .link_to_perturbed (mols , map = property_map )
1199+ else :
1200+ mols = _sr .morph .link_to_reference (mols , map = property_map )
1201+
1202+ # Try to get the coordinates array.
1203+ try :
1204+ coords = _sr .io .get_coords_array (mols , map = property_map )
1205+ except Exception as e :
1206+ msg = "Failed to extract coordinates from system!"
1207+ if _isVerbose ():
1208+ raise RuntimeError (msg ) from e
1209+ else :
1210+ raise RuntimeError (msg ) from None
1211+
1212+ return coords
1213+
1214+ def setCoordinates (
1215+ self ,
1216+ coordinates ,
1217+ is_lambda1 = False ,
1218+ property_map = {},
1219+ ):
1220+ """
1221+ Set the coordinates of all atoms in the system from a NumPy array.
1222+ Coordinates are expected to be in Angstroms.
1223+
1224+ Parameters
1225+ ----------
1226+
1227+ coordinates : numpy.ndarray
1228+ The coordinates of all atoms in the system in Angstroms.
1229+
1230+ is_lambda1 : bool
1231+ Whether to set the coordinates at lambda = 1 for perturbable molecules.
1232+
1233+ property_map : dict
1234+ A dictionary that maps system "properties" to their user defined
1235+ values. This allows the user to refer to properties with their
1236+ own naming scheme, e.g. { "charge" : "my-charge" }
1237+ """
1238+
1239+ import numpy as _np
1240+
1241+ # Validate input.
1242+ if not isinstance (coordinates , _np .ndarray ):
1243+ raise TypeError ("'coordinates' must be of type 'numpy.ndarray'" )
1244+ if coordinates .ndim != 2 or coordinates .shape [1 ] != 3 :
1245+ raise ValueError ("'coordinates' must be a 2D array with shape (n_atoms, 3)" )
1246+ if coordinates .shape [0 ] != self .nAtoms ():
1247+ raise ValueError (
1248+ "'coordinates' must have the same number of atoms as the system"
1249+ )
1250+
1251+ if not isinstance (is_lambda1 , bool ):
1252+ raise TypeError ("'is_lambda1' must be of type 'bool'" )
1253+
1254+ if not isinstance (property_map , dict ):
1255+ raise TypeError ("'property_map' must be of type 'dict'" )
1256+
1257+ # Set the coordinates.
1258+ try :
1259+ self ._sire_object = _SireIO .setCoordinates (
1260+ self ._sire_object ,
1261+ coordinates .tolist (),
1262+ is_lambda1 ,
1263+ map = property_map ,
1264+ )
1265+ except Exception as e :
1266+ msg = "Failed to set coordinates in system!"
1267+ if _isVerbose ():
1268+ raise RuntimeError (msg ) from e
1269+ else :
1270+ raise RuntimeError (msg ) from None
1271+
11611272 def rotateBoxVectors (
11621273 self ,
11631274 origin = _Coordinate (
0 commit comments