@@ -534,6 +534,25 @@ def _addMissingResiduesToChain(self, chain, residueNames, startPosition, endPosi
534
534
templatePosition = template .positions [atom .index ].value_in_unit (unit .nanometer )
535
535
newPositions .append (mm .Vec3 (* np .dot (rotate , templatePosition ))* unit .nanometer + translate )
536
536
537
+ def _renameNewChains (self , startIndex ):
538
+ """Rename newly added chains to conform with existing naming conventions.
539
+
540
+ Parameters
541
+ ----------
542
+ startIndex : int
543
+ The index of the first new chain in self.topology.chains().
544
+ """
545
+ # If all chains are new, nothing to do
546
+ if startIndex == 0 :
547
+ return
548
+
549
+ # If the last chain ID was originally a letter, continue alphabetically until reaching Z
550
+ chains = list (self .topology .chains ())
551
+ for newChainIndex in range (startIndex , len (chains )):
552
+ prevChainId = chains [newChainIndex - 1 ].id
553
+ if len (prevChainId ) == 1 and "A" <= prevChainId < "Z" :
554
+ chains [newChainIndex ].id = chr (ord (prevChainId ) + 1 )
555
+
537
556
def removeChains (self , chainIndices = None , chainIds = None ):
538
557
"""Remove a set of chains from the structure.
539
558
@@ -1092,16 +1111,13 @@ def addSolvent(self, boxSize=None, padding=None, boxVectors=None, positiveIon='N
1092
1111
1093
1112
"""
1094
1113
1114
+ nChains = sum (1 for _ in self .topology .chains ())
1095
1115
modeller = app .Modeller (self .topology , self .positions )
1096
1116
forcefield = self ._createForceField (self .topology , True )
1097
1117
modeller .addSolvent (forcefield , padding = padding , boxSize = boxSize , boxVectors = boxVectors , boxShape = boxShape , positiveIon = positiveIon , negativeIon = negativeIon , ionicStrength = ionicStrength )
1098
- chains = list (modeller .topology .chains ())
1099
- if len (chains ) == 1 :
1100
- chains [0 ].id = 'A'
1101
- else :
1102
- chains [- 1 ].id = chr (ord (chains [- 2 ].id )+ 1 )
1103
1118
self .topology = modeller .topology
1104
1119
self .positions = modeller .positions
1120
+ self ._renameNewChains (nChains )
1105
1121
1106
1122
def addMembrane (self , lipidType = 'POPC' , membraneCenterZ = 0 * unit .nanometer , minimumPadding = 1 * unit .nanometer , positiveIon = 'Na+' , negativeIon = 'Cl-' , ionicStrength = 0 * unit .molar ):
1107
1123
"""Add a lipid membrane to the structure.
@@ -1124,16 +1140,14 @@ def addMembrane(self, lipidType='POPC', membraneCenterZ=0*unit.nanometer, minimu
1124
1140
ionicStrength : openmm.unit.Quantity with units compatible with molar, optional, default=0*molar
1125
1141
The total concentration of ions (both positive and negative) to add. This does not include ions that are added to neutralize the system.
1126
1142
"""
1143
+
1144
+ nChains = sum (1 for _ in self .topology .chains ())
1127
1145
modeller = app .Modeller (self .topology , self .positions )
1128
1146
forcefield = self ._createForceField (self .topology , True )
1129
1147
modeller .addMembrane (forcefield , lipidType = lipidType , minimumPadding = minimumPadding , positiveIon = positiveIon , negativeIon = negativeIon , ionicStrength = ionicStrength )
1130
- chains = list (modeller .topology .chains ())
1131
- if len (chains ) == 1 :
1132
- chains [0 ].id = 'A'
1133
- else :
1134
- chains [- 1 ].id = chr (ord (chains [- 2 ].id )+ 1 )
1135
1148
self .topology = modeller .topology
1136
1149
self .positions = modeller .positions
1150
+ self ._renameNewChains (nChains )
1137
1151
1138
1152
def _createForceField (self , newTopology , water ):
1139
1153
"""Create a force field to use for optimizing the positions of newly added atoms."""
0 commit comments