Skip to content
Snippets Groups Projects
Commit 02b65fe7 authored by cmaffeo2's avatar cmaffeo2
Browse files

Brought in changes from mrdna package to arbdmodel.py from commits 8dafa9f..205bb86

parent 5ed0da54
No related branches found
No related tags found
No related merge requests found
...@@ -99,17 +99,21 @@ class Parent(): ...@@ -99,17 +99,21 @@ class Parent():
x.parent = None x.parent = None
def add_bond(self, i,j, bond, exclude=False): def add_bond(self, i,j, bond, exclude=False):
assert( i is not j )
## TODO: how to handle duplicating and cloning bonds ## TODO: how to handle duplicating and cloning bonds
# beads = [b for b in self] # beads = [b for b in self]
# for b in (i,j): assert(b in beads) # for b in (i,j): assert(b in beads)
self.bonds.append( (i,j, bond, exclude) ) self.bonds.append( (i,j, bond, exclude) )
def add_angle(self, i,j,k, angle): def add_angle(self, i,j,k, angle):
assert( len(set((i,j,k))) == 3 )
# beads = [b for b in self] # beads = [b for b in self]
# for b in (i,j,k): assert(b in beads) # for b in (i,j,k): assert(b in beads)
self.angles.append( (i,j,k, angle) ) self.angles.append( (i,j,k, angle) )
def add_dihedral(self, i,j,k,l, dihedral): def add_dihedral(self, i,j,k,l, dihedral):
assert( len(set((i,j,k,l))) == 4 )
# beads = [b for b in self] # beads = [b for b in self]
# for b in (i,j,k,l): assert(b in beads) # for b in (i,j,k,l): assert(b in beads)
self.dihedrals.append( (i,j,k,l, dihedral) ) self.dihedrals.append( (i,j,k,l, dihedral) )
...@@ -326,6 +330,7 @@ class ParticleType(): ...@@ -326,6 +330,7 @@ class ParticleType():
def __hash_key(self): def __hash_key(self):
l = [self.name,self.charge] l = [self.name,self.charge]
for keyval in sorted(self.__dict__.items()): for keyval in sorted(self.__dict__.items()):
if isinstance(keyval[1], list): keyval = (keyval[0],tuple(keyval[1]))
l.extend(keyval) l.extend(keyval)
return tuple(l) return tuple(l)
...@@ -622,7 +627,7 @@ class PdbModel(Transformable, Parent): ...@@ -622,7 +627,7 @@ class PdbModel(Transformable, Parent):
class ArbdModel(PdbModel): class ArbdModel(PdbModel):
def __init__(self, children, dimensions=(1000,1000,1000), temperature=291, timestep=50e-6, cutoff=50, decompPeriod=10000, pairlistDistance=None, nonbondedResolution=0.1, remove_duplicate_bonded_terms=True): def __init__(self, children, dimensions=(1000,1000,1000), temperature=291, timestep=50e-6, cutoff=50, decompPeriod=10000, pairlistDistance=None, nonbondedResolution=0.1, remove_duplicate_bonded_terms=True, extra_bd_file_lines=""):
PdbModel.__init__(self, children, dimensions, remove_duplicate_bonded_terms) PdbModel.__init__(self, children, dimensions, remove_duplicate_bonded_terms)
self.temperature = temperature self.temperature = temperature
...@@ -635,6 +640,8 @@ class ArbdModel(PdbModel): ...@@ -635,6 +640,8 @@ class ArbdModel(PdbModel):
self.decompPeriod = decompPeriod self.decompPeriod = decompPeriod
self.pairlistDistance = pairlistDistance self.pairlistDistance = pairlistDistance
self.extra_bd_file_lines = extra_bd_file_lines
self.numParticles = 0 self.numParticles = 0
self.particles = [] self.particles = []
self.type_counts = None self.type_counts = None
...@@ -697,7 +704,7 @@ class ArbdModel(PdbModel): ...@@ -697,7 +704,7 @@ class ArbdModel(PdbModel):
if typeA != typeB: if typeA != typeB:
self.nbSchemes.append( (nbScheme, typeB, typeA) ) self.nbSchemes.append( (nbScheme, typeB, typeA) )
def simulate(self, output_name, output_directory='output', num_steps=100000000, timestep=None, gpu=0, output_period=1e4, arbd=None, directory='.', replicas=1): def simulate(self, output_name, output_directory='output', num_steps=100000000, timestep=None, gpu=0, output_period=1e4, arbd=None, directory='.', replicas=1, log_file=None):
assert(type(gpu) is int) assert(type(gpu) is int)
num_steps = int(num_steps) num_steps = int(num_steps)
...@@ -753,10 +760,16 @@ class ArbdModel(PdbModel): ...@@ -753,10 +760,16 @@ class ArbdModel(PdbModel):
cmd = tuple(str(x) for x in cmd) cmd = tuple(str(x) for x in cmd)
print("Running ARBD with: %s" % " ".join(cmd)) print("Running ARBD with: %s" % " ".join(cmd))
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True) if log_file is None or (hasattr(log_file,'write') and callable(log_file.write)):
for line in process.stdout: fd = sys.stdout if log_file is None else log_file
sys.stdout.write(line) process = subprocess.Popen(cmd, stdout=subprocess.PIPE, universal_newlines=True)
sys.stdout.flush() for line in process.stdout:
fd.write(line)
fd.flush()
else:
with open(log_file,'w') as fd:
process = subprocess.Popen(cmd, stdout=log_file, universal_newlines=True)
process.communicate()
except: except:
raise raise
...@@ -851,6 +864,8 @@ pairlistDistance {pairlistDistance} ...@@ -851,6 +864,8 @@ pairlistDistance {pairlistDistance}
origin {originX} {originY} {originZ} origin {originX} {originY} {originZ}
systemSize {dimX} {dimY} {dimZ} systemSize {dimX} {dimY} {dimZ}
{extra_bd_file_lines}
\n""".format(**params)) \n""".format(**params))
## Write entries for each type of particle ## Write entries for each type of particle
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment